Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 488
  • Last Modified:

timer on form in vb.net

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
rutledgj
Asked:
rutledgj
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
nffvrxqgrcfqvvcCommented:
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
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
...move your DB operations to a different thread...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
rutledgjAuthor Commented:
egl1044: I just tried this but it doesn't seem to work either. It doesn't update the label on the main form.
0
 
rutledgjAuthor Commented:
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
 
nffvrxqgrcfqvvcCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"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
 
rutledgjAuthor Commented:
Since neither solution is feasable without rewriting my code I'll just spread the points to the most logical.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now