开发者

Windows Service is started but does not do anything - .NET

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 lo开发者_如何学Gog4net 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() or GetTimerInterval() throws an exception, so that timer.Start() is not executed?

Then you should maybe wrap that part in a try..catch and/or add some logging, e.g:

timer.Stop();
try
{
  //process some stuff here..
  ProcessStuff();
}
catch (Exception ex)
{
  // log the exception?
}
timer.Interval = GetTimerInterval();
timer.Start();


I have two ideas for you. One create a dump and see what is up or use the remote debugger and see what you are locking on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜