By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,179 Members | 2,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,179 IT Pros & Developers. It's quick & easy.

Timer Control - No Longer Asynchronous?

P: n/a
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

Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <no******@mailingspam.com> wrote in message
news:eS***************@TK2MSFTNGP09.phx.gbl...
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

Jul 21 '05 #2

P: n/a
David wrote:
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

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..
Jul 21 '05 #3

P: n/a
> 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.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.754 / Virus Database: 504 - Release Date: 9/6/2004
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.