Fire timer_elapsed immediately from OnStart in windows service

前端 未结 4 1407
情话喂你
情话喂你 2021-02-13 20:33

I\'m using a System.Timers.Timer and I\'ve got code like the following in my OnStart method in a c# windows service.

timer = new Timer(         


        
4条回答
  •  逝去的感伤
    2021-02-13 21:13

    Use System.Threading.Timer class instead of System.Timers.Timer as this type is just a wrapper for Threading Timer.

    It also suits your requirement.

     System.Threading.Timer timer =
                    new System.Threading.Timer(this.DoWork, this, 0, 36000);
    

    Here are the details.

提交回复
热议问题