Timer Control - No Longer Asynchronous?

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi There!

I'm using Timer control to record how long my application perform certain
tasks.

However, apparently Timer control is not doing its' job (i.e. Not firing
Tick event) while my application is busy. So even if my application took 2
mins, the label that is used to show the number of seconds elapsed will
still say "2 seconds".

While the application is not busy, I enabled the Timer and the second count
increases normally every second.

Is this means Timer control in VB.NET is not Asynchronous (like VB6 Timer
control) ? Or am I missing something? Please help!!!

Thanks in advance!!!

David
 
The System.Windows.Forms.Timer runs on the same thread as the application.
So if your application is carrying out some processor-intensive task, the
timer ticks are not going to be fired since the thread is busy doing your
task. Instead, use the System.Timers.Timer (which runs on a seperate thread
than the application) and write your code in the Elapsed event of the timer.

hope that helps..
Imran.
 
David said:
Is this means Timer control in VB.NET is not Asynchronous (like VB6 Timer
control) ? Or am I missing something? Please help!!!

The VB6 Timer control was never asynchronous. It worked exactly the same
as every other event driven component. When an event fires, the programs
instruction pointer is saved and then moved to the top of the event
handler procedure and will be returned to the saved address when the End
Sub runs in that event handler procedure.

Private Sub ABC()
1 code here
2 code here
3 code here
'timer event fires after running line 3
'code in timer's event handler runs
'returns to line 4 after the End Sub in the timer event
4 code here
5 code here
6 code here
End Sub

Private Sub Timer1_Timer()
'This entire procedure runs before
'returning to line 4 above
'it will never return until the line below runs
End Sub
 
I'm using Timer control to record how long my application perform certain
tasks.

However, apparently Timer control is not doing its' job (i.e. Not firing
Tick event) while my application is busy. So even if my application took 2
mins, the label that is used to show the number of seconds elapsed will
still say "2 seconds".

Maybe you should use dateTime instead of a timer control.
COmpare the time before the task to the time after the task.
 
Back
Top