Solved

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

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

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

912 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

17 Experts available now in Live!

Get 1:1 Help Now