Threading, Progress Indicator, etc.

BenjaminRay

New member
Joined
Aug 3, 2005
Messages
3
Programming Experience
1-3
Hey all,

I am having trouble accurately knowing when a thread has completed without holding up my application with loops & the like.

My basic goal is this: Run a recursive directory/file search program, and provide the user with a small progress indicator form with a Cancel option while they wait.

The search function runs as a thread, which allows the main form and the progress indicator form to continue to function while the work is being done. However, it's when I try to track the completion of the thread that I end up disabling the forms with either a loop or by telling it to wait for AutoResetEvent.WaitOne.

The problem is that when the main application is waiting for the event, it is completely frozen, which defeats the purpose of using a thread in the first place. And if I create a second thread to allow the progress indicator form to open up while the main application is held up, it doesn't stay open. (Why would it? The thread is told to open it, and it aborts when it has done its job.)

In the end, I my code is now more complicated, but I still have no access to either of the forms while I wait for the search to complete.

Can any of you help me out with this? It seems like checking for the thread's completion can't be done without holding up the entire application.

Thanks.
 
I dont know if this will work, but try doing something like

VB.NET:
Do Until threadComplete = True
  Application.DoEvents
Loop

where threadComplete is a boolean that is set to true when the thread completes. Hopefully the GUI should be stuck in a loop, where it still responds, but cant exit until the thread completes.
 
Works perfectly!

You are the man. That works perfectly.

I had NO idea about DoEvents. That solves the problem of tying up the entire application with loops while waiting for something else to happen.

I've been programming primarily in ASP.Net, so some of the basic Windows.Forms stuff is new to me.

Thank you so much!

Benjamin Ray

tomhosking said:
I dont know if this will work, but try doing something like

VB.NET:
Do Until threadComplete = True
Application.DoEvents
Loop

where threadComplete is a boolean that is set to true when the thread completes. Hopefully the GUI should be stuck in a loop, where it still responds, but cant exit until the thread completes.
 
Im glad, 'cause Im about to write some code that relies on that :D

Youre lucky to have a background in VB-style languages, until monday I'd only ever used perl/PHP, but some software needed doing in VB this week - google has been invaluable ;)
 
Yep...

Yep, it works great. I wasn't sure what Application.DoEvents would allow, but it apparently has few limits (if any). Other subs and threads can be spawned off, meanwhile the original loop sits there doing its thang.

Yep, I started with VB a few years back, but so far I've written it in every possible application EXCEPT windows forms. (VBScript, ASP, ASP.Net, Excel, etc.)

Google is great, and there's tons of VB.Net stuff out there.

Good luck, and thanks again!


tomhosking said:
Im glad, 'cause Im about to write some code that relies on that :D

Youre lucky to have a background in VB-style languages, until monday I'd only ever used perl/PHP, but some software needed doing in VB this week - google has been invaluable ;)
 
Back
Top