Solved

timer on form in vb.net

Posted on 2010-08-23
8
483 Views
Last Modified: 2012-05-10
I have an app that I want to display a timer that updates every second. The problem is that the display hangs while the app is doing database fetches.

Is there a way to make the timer update an independent thread so it is unaffected by the other processes?

Thanks,
0
Comment
Question by:rutledgj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 29

Assisted Solution

by:nffvrxqgrcfqvvc
nffvrxqgrcfqvvc earned 75 total points
ID: 33504199
You will have to use one of the timers that don't associate the forms handle with the timer.

System.Threading.Timer
http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx 
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33504396
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33504439
...move your DB operations to a different thread...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rutledgj
ID: 33504493
egl1044: I just tried this but it doesn't seem to work either. It doesn't update the label on the main form.
0
 

Author Comment

by:rutledgj
ID: 33504534
moving dbops to another thread probably isn't an option at this point since the application is basically complete. Just trying to display a timer.

Besides, the timer hangs during logic processing as well as db fetches. I guess I need something completely independent of what the frmMain is doing.
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 33504751
Yeah, I only seen you wanted to execute a Timer every second there was no mention of updating  control or label from the timer on the form. The timer should work but your problem is not the timer anymore it's no message can be updated on your form because of your database routine. You will have to use the other experts alternative above so that your form can still process messages to update the controls.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 225 total points
ID: 33504767
"I guess I need something completely independent of what the frmMain is doing."

You can't.  ALL control updates run in the SAME main UI thread.  If frmMain is busy doing DB operations or "logic processing" then it ALSO CANNOT update the current time.

You either need to:
(1) Correctly move processing to another thread.
(2) Pepper your code with "Application.DoEvents()"
0
 

Author Closing Comment

by:rutledgj
ID: 33504787
Since neither solution is feasable without rewriting my code I'll just spread the points to the most logical.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question