使用计时器在下午4点执行特定任务

时间:2016-05-08 22:01:46

标签: c# winforms

我尝试做的是使用计时器来检查当前时间。一旦满足条件。 (现在是下午4点)然后我想播放一个音频文件。最后,计时器应该停止,直到第二天才会发生任何事情。

public partial class Form1 : Form
 {
     public Form1()
     {
         InitializeComponent();
     }

     const double interv = 1000; 
     System.Timers.Timer xtime = new System.Timers.Timer(interv);

     private void Form1_Load(object sender, EventArgs e)
     {
         xtime.Elapsed += new ElapsedEventHandler(checkForTime_Elapsed);
         xtime.Enabled = true;
     }


     public void xtime _Elapsed(object sender, ElapsedEventArgs e)
     {

         DateTime reach = new DateTime(2016, 5, 8, 11, 58, 0);
         DateTime now = DateTime.Now;

         if (target.ToString("HH:mm:ss") == now.ToString("HH:mm:ss")
         {
             MessageBox.Show("Your time is up.  GOODBYE");
             xtime.Stop();
             xtime .Enabled = false;
         }
     }
 }

使用上面的代码没有任何反应。

我做错了什么?

0 个答案:

没有答案