System.Timers.Timer

  • Thread starter Thread starter cntams
  • Start date Start date
C

cntams

All,
I have a Windows Service and it has one System.Timers.Timer that
fires every 500 milliseconds. Now I have noticed that there's a bug in
System.Timers.Timer when it's being used combined with Windows Service.
That is, the Timer won't fire again once it's stopped (Timer.Stop() or
Timer.Enabled = False) (http://support.microsoft.com/kb/842793/en-us).
Instead of using Threading.Timer, can I just have the code to run
inside the System.Timers.Timer Handler? However, this block of code
would take at least one or two seconds to run and it will go into the
database (using ADO). Would this cause a new Timer (Thread) to fire
since the process time is actually greater than the elapsed time?

Sample Code
Sub Timer1_TimerCallBack(ByVal source As Object, ByVal e As
Timers.ElapsedEventArgs)
'Don't stop the timer...

'Calling a sub and processing it.
DoSomthing()

End Sub

Private Sub DoSomthing()
'Processing and accessing the database...
End Sub


Thanks,
Carl
 
I am using the System.Timers.Timer in a service and do not have a problem. In
the "Elapsed" event handler I toggle the "enabled" property before/after
processing.
 
I use timers all the time in windows services.

Why aren't you using the tick event?
 
Back
Top