Timer problem with windows service
-
Dear All, I have set a timer for my windows service using Threading.Timer. I set the interval to 10000 that is 10s before finished its current job. The problem is the oCallback is called every 10000, can someone help me so that the oCallback will not fires before finish it current job.
Dim oCallback As New TimerCallback(AddressOf OnTimedEvent) oTimer = New System.Threading.Timer(oCallback, Nothing, 0, 10000) Private Sub OnTimedEvent(ByVal state As Object) 'need to stop timer.. EventLog1.WriteEntry("Called") System.threading.thread.sleep(20000)' just to delay for 20 sec 'start timer back End Sub
Thank you in advance.
awek
Programmer Subang Jaya,Selangor, Malaysia -
Dear All, I have set a timer for my windows service using Threading.Timer. I set the interval to 10000 that is 10s before finished its current job. The problem is the oCallback is called every 10000, can someone help me so that the oCallback will not fires before finish it current job.
Dim oCallback As New TimerCallback(AddressOf OnTimedEvent) oTimer = New System.Threading.Timer(oCallback, Nothing, 0, 10000) Private Sub OnTimedEvent(ByVal state As Object) 'need to stop timer.. EventLog1.WriteEntry("Called") System.threading.thread.sleep(20000)' just to delay for 20 sec 'start timer back End Sub
Thank you in advance.
awek
Programmer Subang Jaya,Selangor, MalaysiaHi Can you tell how much time it is taking to process the current job?Is it taking more than 10 sec? You can declare a boolean variable with value flase.S et it's value to true after completing the current job and check the value of boolean variable if it is true then only move forwad otherwise return from the time function...
-
Dear All, I have set a timer for my windows service using Threading.Timer. I set the interval to 10000 that is 10s before finished its current job. The problem is the oCallback is called every 10000, can someone help me so that the oCallback will not fires before finish it current job.
Dim oCallback As New TimerCallback(AddressOf OnTimedEvent) oTimer = New System.Threading.Timer(oCallback, Nothing, 0, 10000) Private Sub OnTimedEvent(ByVal state As Object) 'need to stop timer.. EventLog1.WriteEntry("Called") System.threading.thread.sleep(20000)' just to delay for 20 sec 'start timer back End Sub
Thank you in advance.
awek
Programmer Subang Jaya,Selangor, MalaysiaJust a thought, but why not stop the timer in your OnTimedEvent handler?? You've got the thing setup with a callback and an interval, so all you need to do at the end of the job is start the timer. At the beginning of the job, stop it.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Just a thought, but why not stop the timer in your OnTimedEvent handler?? You've got the thing setup with a callback and an interval, so all you need to do at the end of the job is start the timer. At the beginning of the job, stop it.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008