I have a .NET Windows Service (.NET 3.5) with a timer (System.Timers.Timer). The OnElapsed method looks like this:
private void OnTimerElapsed(object source, ElapsedEventArgs e)
{
lock (this)
{
timer.Stop();
//process some stuff here..
ProcessStuff();
timer.Interval = GetTimerInterval();
timer.Start();
}
}
It works fine until it mysteriously stops working. This happens every x days and although the service has a status of started, it does not kick off the ProcessStuff() method. I use log4net and nothing is logged there or in the Windows Event logs. The ProcessStuff() spawns multiple threads to do some work.
How do I resolve this?
Is it possible that
ProcessStuff()orGetTimerInterval()throws an exception, so thattimer.Start()is not executed?Then you should maybe wrap that part in a
try..catchand/or add some logging, e.g: