tags:

views:

126

answers:

4

I am running several long synchronous operations in my VB.NET application that can take several minutes each to complete. During these operations the form will turn white and the title bar will show "Not Responding" and some users may close the application thinking it has stopped working when in fact it is still running.

I am pretty sure I need to multithread to do this, but my initial efforts have been unsuccessful. What is the easiest way to refresh my form every couple of seconds or so while these long operations are running?

+6  A: 

Take a look at the BackgroundWorker class.

Konamiman
I'd upvote if you'd include an example of how using this would solve the OPs problem. As it is, the answer is only marginally helpful.
tvanfosson
+1 The link provides a perfectly good example.
Nifle
@Nifle -- so quote the example code here to improve the answer or, in this case, because the sample code is long, describe how you would use the class to address the problem. I'd like to see a more complete answer here because if the link breaks this answer would be rendered virtually useless. When answering you need to try and remember that eventually the answer needs to stand on its own regardless of the resources it links to.
tvanfosson
That is my issue some of the microsoft examples seem overly complex and more confusing then helpful. I have already seen these examples, but find them somewhat difficult to follow. I am looking for something a little more simplified.
Matt
@Matt - I find that the opposite is worse: Uselessly trivial examples.
SnOrfus
+1  A: 

You can use Apllication.DoEvents

astander
This can cause other problems, like re-entrancy issues.
Joel Coehoorn
A: 

Look into Control.BeginInvoke too.

This SO post will be useful:
UI still non responsive after using control.begininvoke

o.k.w
+1  A: 

There's a good demo of the BackgroundWorker class here. Basically, you need to execute the task in the background and periodically have it update the main thread with it's status by raising events that are caught by your main thread. The BackgroundWorker class has all the functionality you need to this for most situations. Running the task in the background will keep your application responsive.

TLiebe