Windows Service Question

G

Guest

Using multiple System.Timers.Timer objects in a Windows Service for
performing multi-thread activities in a periodic fashion. Timers are
AutoReset=false, to only have a single timer execution thread running at any
given moment.

Typically, timers will have an interval of 5 to 15 minutes. Conditionally,
the interval may be set to 1 second (1000 ms) before the next call to
Timer.Start().

Here is the question: if the interval is one second before the call to
Timer.Start(), what will happen if the server clock time is changed...forward
or backward...by more than one second, or less than a second???

I have my suspicions on the answer to this question....looking for other
feedback to validate my thoughts.
 
K

Kevin Spencer

Timers do not operate based on time. They work based on ticks of the
processor clock.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

I recycle.
I send everything back to the planet it came from.
 
G

Guest

Agreed on the processor clock triggering the timer event...I am chasing down
a problem with a multi threaded service...is has the characteristic behavior
that the Timers simply stop firing.

I am finding several other posts on similar sounding issues...yet to find
one that has an acknowledgement, or a solution.

I asked the question about the clock time change and the timer, as I see
clock sync events being logged on the server....grasping for straws here...

Any ideas?
 
J

John Duval

Are you definitely using System.Timers.Timer and not
System.Threading.Timer?

You might want to check out this article:
FIX: When a .NET Framework based application uses the
System.Threading.Timer class, the timer event may not be signaled in
the .NET Framework 1.1 SP1

http://support.microsoft.com/?id=900822
 
K

Kevin Spencer

Hi Tom,

I can certainly understand your frustration. I have written a number of
services that use the System.Timers.Timer class, and they are all
multi-threaded. In fact, they all derive from the same base class, which is
not a Windows service at all, but a business class that is designed to run
in a Windows service. I built it that way so I could test it (and/or use it)
in an application that is not a Windows service. But it is designed with
Windows Services in mind, as it has a method to call for each Service method
(Start, Run, Stop, etc).

The main difference I see (from here at this point) between what you're
doing and what I'm doing is that I do not set the AutoReset property to
false. Instead, I can set the Enabled property to false to stop the timer,
and to true to restart it. I'm not at all sure what problem could be caused
by setting AutoReset to false and "manually" restarting it in that fashion.

Since we're both a bit stumped, I can suggest a workaround. Set the
AutoReset property to true, and use the Enabled property to start and stop
the Timer. At the very least that will give you some data that you can
compare against your current results, and possibly help with the diagnostic
process.

In a multi-threaded application, you might consider using a ThreadPool to
manage the threads, and/or some combination of Monitor, Mutex, and/or
Semaphore to handle the synchronization.

Wish I could be of more help, but that's about all I can suggest at the
moment.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

I recycle.
I send everything back to the planet it came from.
 
C

Christopher Carnahan

All the looking I have done suggests that you should use
System.Threading.Timer instead of System.Timers.Timer. And even after
you've made that change, you'll still have the problem where the timers stop
firing for no reason, if you are running on Windows 2003 SP1. The problem
is acknowledged here:

http://support.microsoft.com/?kbid=900822

I upgraded to .Net 2.0, and the timer firing issue went away.

- Christopher
 

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