比如:我要在20:20:30到次日10:20:25这段时间,去执行某个事件!这个时间比较怎么写呢!初学c#,望高手们指点一下。谢谢!

解决方案 »

  1.   

     private Timer timer1;
            public Form1()
            {
                InitializeComponent();
                this.timer1 = new System.Windows.Forms.Timer(this.components);
                this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            }
            private void timer1_Tick(object sender, EventArgs e)
            {
                DateTime dt1 = new DateTime(2009, 10, 15, 20, 30, 0);
                DateTime dt2 = new DateTime(2009, 10, 16, 10, 30, 0);
                if (DateTime.Now.CompareTo(dt1) > 0 && DateTime.Now.CompareTo(dt2) < 0)
                {
                    //执行事件
                    MessageBox.Show("执行事件");
                }
            }
      

  2.   

    最简单的方法:
    while(true)
    {
      if(20:20:30到次日10:20:25)
      {
        //do
      }}
      

  3.   

    3楼的差不多!但是有个问题,就是 我想是这样把时间段分开,今天20:20:30到23:59:59,加上(and) 00:00:00到10:20:25 !这样行不行呢
      

  4.   

    1,2楼的结合起来,在新线程中使用timer,
    有多个定时任务情况下,可以建立多个线程或使用多个timer