How to fire timer.Elapsed event immediately

前端 未结 10 1209
独厮守ぢ
独厮守ぢ 2020-12-10 00:17

I\'m using the System.Timers.Timer class to create a timer with an Timer.Elapsed event. The thing is the Timer.Elapsed event is fired

10条回答
  •  遥遥无期
    2020-12-10 01:03

    not sure about System.Timers.Timer but try

    System.Threading.Timer T = new System.Threading.Timer(new TimerCallback(DoSomething), null, 0, 30000);
    

    This starts immediately (0 milliseconds for first run, 30000 milliseconds for subsequents runs)...

    see
    http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx
    http://msdn.microsoft.com/en-us/library/2x96zfy7.aspx

提交回复
热议问题