Solved

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

Posted on 2013-11-12
2
6,816 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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