Timer use in a windows service

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this simple windows service, it uses a timer that calls a routine
every 10 minutes. Usually this routine takes about 30 seconds to run but
sometimes it might run for 15 minutes under some circumstances, this is
supposed to happen.

What happens when the timer event gets (or should be) raised even if my
routine is still running. Is the routine exited and called again, is the
routine called again right after it's done because the timer elapsed during
its run (this is what my tests suggested here) ?

In short, it seems the decent thing to to is to stop the timer when the
routine gets called and start it again when it's done but is it dangerous to
leave it running even if it might elapse while the routine is running ?
 
What I usually do with timer-based functionality like this is to set
the timer to fire only *after* the long-running algorithm is finished.
For example, the last line of code in the long-running method would be
to set the timer to fire at the next appropriate interval. That might
be what you are alluding to in the last paragraph of your original
post.

HTH,

--steve
 
That's what I do, in the event handler I set enabled to false at the
beginning and true at the end.
 
Back
Top