System.Timers.Timer

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
 
G

Guest

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.
 
J

John A. Bailo

I use timers all the time in windows services.

Why aren't you using the tick event?
 

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