Solved

timer on form in vb.net

Posted on 2010-08-23
8
480 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Form design in vb.net 7 35
VB.Net - For Loop Error 5 37
Protecting vb6 & .Net code Obfuscation 18 97
Show/Hide ASP.NET controls with JQuery best practices 3 20
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

21 Experts available now in Live!

Get 1:1 Help Now