Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

18 Experts available now in Live!

Get 1:1 Help Now