Timer tick event is not called in windows service

后端 未结 5 1334
梦如初夏
梦如初夏 2021-01-06 13:29

I have a window service which plays a sound file at a specified time, so to do that I have taken Timer but it\'s Tick event is never fired, same is working in WinForm applic

5条回答
  •  臣服心动
    2021-01-06 14:16

    I think System.Timers.Timer is a better choice :

    Timer _timer = new Timer();
    // In miliseconds 60000 = 1 minute
    // This timer will tick every 1 minute
    _timer.Interval += 6000;
    // Activate the timer
    _timer.Enabled = true;
    // When timer "tick"
    _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
    

提交回复
热议问题