Solved

URGENT! - VB.NET - Display a running ProgressBar while loading a form

Posted on 2013-11-12
2
7,068 Views
Last Modified: 2013-11-14
I have a few forms in my application which take a long time to load due to the forms retrieving data from the database.  How can I show the user that the forms are indeed working and are not "frozen" as they appear?  I would like to use a ProgressBar if possible.

From past reading, I saw that you may have to use different threads to accomplish this.  I am a newbie to multi-threading, asynchronous processing so I would appreciate if there are any entry level examples that employ this technique.

Thanks!
0
Comment
Question by:eq2006
2 Comments
 
LVL 15

Accepted Solution

by:
unknown_routine earned 500 total points
ID: 39641938
"I am a newbie to multi-threading,"

For you the prefect way to go is using a Background worker Control.


The good thing about using BackGround worker is that you don't need to worry about Thread deadlocks and Thread Events will be fire back on the GUI thread.


See this For a complete tutoriall on how to implement it:

http://www.dreamincode.net/forums/topic/88605-the-background-worker/
0
 
LVL 10

Expert Comment

by:joriszwaenepoel
ID: 39642991
You have a few options:

1. Postpone the time-consuming code until the form has loaded.  In the Form_Load, start a Windows Forms Timer with a short interval (50 ms for example).  Then, when the timer elapses, stop the timer (avoid that it fires more than once) and do the time-consuming work.  It will take just as long, and the form will not be usable during the data-retrieval, but it will be painted nicely before the data-retrieval begins.  Maybe this is already good enough.

2. Next, and probably better, is to start a backgroundworker, and do the time-consuming stuff on the background thread.  However, you cannot modify any UI element on the background thread.  You need to use the "ProgressChanged" or "RunWorkerCompleted" events (that are called on the correct UI thread automatically) for the UI related work.

3. Other Multi-threading options exist, but are probably too complicated for what you need to do.  

Also, make suer you do the database-querying as efficient as possible.  I don't know how you query your database, but maybe you can avoid a lot of the "long time to load" by optimizing the database access code.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

680 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