System.Timers.Timer timer1_Elapsed not firing! Help!

前端 未结 4 672
陌清茗
陌清茗 2021-01-22 22:14

I am creating another windows service and my timer is not ticking and I have no idea why! I am using system.timers.timer as I have in previous services and it doesn\'t work. I

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-22 23:16

    I think timer1_Elapsed needs to use the event delegate, so

    timer1_Elapsed +=  new ElapsedEventHandler(timer1_Elapsed);
    

    http://msdn.microsoft.com/es-es/library/system.timers.timer.aspx

    Though I would recommend the System.Threading.Timer for inside a service, as it will correctly throw exceptions inside the elapsed event. System.Timers.Timer just swallows them.

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

提交回复
热议问题