I’m working on a Windows Service with a timer to schedule a job each interval of time.
It seems that the timer elapsed event is fired more than one time.
Here a code sample:
private static System.Timers.Timer _timer = new System.Timers.Timer();
protected override void OnStart(string[] args)
{
_timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
_timer.Interval = 1000;
_timer.Enabled = true;
_timer.Start();
}
private void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
_timer.Enabled = false;
_timer.Stop();
//Do the job
_timer.Enabled = true;
_timer.Start();
}
Can you help me?
Thank you
Quoted from: Timer.Stop Method. Please see the code sample on the page.