我在程序里设了定时器,可是一运行就开始计时,到了设定的间隔时间才开始运行t_Elapsed里的东东。例如:
t.Interval = 6*3600*1000;//6小时运行一次
t.Elapsed += new ElapsedEventHandler(t_Elapsed);程序一开始就要先等6小时才开始运行t_Elapsed,如何能一开始先运行一下t_Elapsed,然后开始计时,过6小时再次运行t_Elapsed?谢谢赐教

解决方案 »

  1.   


    private void button1_Click(object sender, EventArgs e)
    {
        timer1_Tick(null, null);
        timer1.Interval = 6 * 3600 * 1000;
        timer1.Start();
    }private void timer1_Tick(object sender, EventArgs e)
    {
        // ...
    }
      

  2.   

    System.Timers.Timer timer1 = new System.Threading.Timer(new TimerCallback(timer1_Tick), null, 0, 6 * 3600 * 100);
            void timer1_Tick(object sender, ElapsedEventArgs e) 
            { 
               
            } 
    timer1_Tick(null, null);
      

  3.   


    多谢多谢,我开始想到这样做,但是timer1_Tick(null,null)这个地方我写错了~呵呵~谢谢哈