Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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