Solved

timer on form in vb.net

Posted on 2010-08-23
8
470 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
  • 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 69

Expert Comment

by:Éric Moreau
ID: 33504396
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33504439
...move your DB operations to a different thread...
0
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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 85

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now