Windows Service System.Timers.Timer not firing

前端 未结 6 1916
走了就别回头了
走了就别回头了 2020-12-05 04:36

I have a Windows service written in C# which is meant to perform a task every few minutes. I\'m using a System.Timers.Timer for this but it doesn\'t ever appea

6条回答
  •  庸人自扰
    2020-12-05 04:53

    You forget to enable timer by setting:

    IntervalTimer.Enabled = true;
    

    or calling Start method:

    IntervalTimer.Start();
    
    protected override void OnStart(string[] args)
    {
        // Set up the timer...
        IntervalTimer.Interval = Properties.Settings.Default.PollingFreqInSec * 1000;
        // Start the timer and wait for the next work to be released...
        IntervalTimer.Start();
    }
    

提交回复
热议问题