System.Timers.Timer stops firing events

B

Ben Gavin

Hi all,
I have some simple windows service code which fires a timer event every
minute. The code seems to function normally in the Release build of the
client, but when running the debug build of the client (to service our
active development effort), the timer seems to stop sending events after a
(seemingly random) amount of time. I've added tracing into the routine and
this proves out the theory that there is not an error going on in the event
handler. The handler looks like:

tmr_Elapsed(...)
{
try
{
tmr.Stop();

... do stuff ...
}
catch(Exception e)
{
.. log error ..
}
finally
{
tmr.Start();
}
}

This works fine, and I see the trace messages indicating that the timer is
being started/stopped normally, but after the service has been running for a
few hours, the timer just quits. As I said, this only seems to happen in
Debug builds, the release builds that I've deployed can run for weeks on end
without an issue, but the debug build can't even make it an entire day
without getting lost.

Has anyone seen this error before, and found a way to solve it?

Thanks!
Ben
 
F

Fabian Schmied

[...]
This works fine, and I see the trace messages indicating that the timer is
being started/stopped normally, but after the service has been running for a
few hours, the timer just quits. As I said, this only seems to happen in
Debug builds, the release builds that I've deployed can run for weeks on end
without an issue, but the debug build can't even make it an entire day
without getting lost.

Has anyone seen this error before, and found a way to solve it?

This has been brought up a few times at discuss.develop.com (e.g.
http://tinyurl.com/qwlr, read from bottom to top). Apperently, the best
workaround seems to be to use System.Threading.Timer instead.

hth
Fabian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top