Timer in a Windows Service not firing?

J

james

Hi all.
I have a service I am writing. The last step of the onLoad event is to
enable a timer, however this timer never seems to fire. I have added a line
of code after the timer enable line to write the status to the event log,
and this definitely says the enabled property is true... but I have also put
an event-log-writing line as the first step in the timer firing event, and
this never gets logged.

Is there something weird I am missing to do with services? Err...
James.
 
C

Chris Dunaway

james said:
Hi all.
I have a service I am writing. The last step of the onLoad event is to
enable a timer, however this timer never seems to fire. I have added a line
of code after the timer enable line to write the status to the event log,
and this definitely says the enabled property is true... but I have also put
an event-log-writing line as the first step in the timer firing event, and
this never gets logged.

Is there something weird I am missing to do with services? Err...

What kind of timer did you use? You should not use the
System.Windows.Forms.Timer as that will not work in a service. You
should use a System.Timers.Timer or a System.Threading.Timer instead.
 
C

Claes Bergefall

What kind of timer? And which onLoad event are you refering to?
If you're trying to put UI stuff in your service, then please rethink your
design.

/claes
 
J

james

Claes Bergefall said:
What kind of timer? And which onLoad event are you refering to?
If you're trying to put UI stuff in your service, then please rethink your
design.

A forms timer - I think Chris has hit on the answer as well. Rather than
dragging the timer into the service "designer", I should just create a
system timer in code instead. My service definitely doesn't have or need any
UI stuff, I just forgot that the timer in the toolbox isn't the same thing!
Thanks guys.
 

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