Link to home
Start Free TrialLog in
Avatar of mebjen
mebjen

asked on

How do I suspend the current Thread until progressBar is finished??

Gurus,

I need your help - I have a VB .NET Windows App that loads a form with data and if a certain criteria is met, displays a messageBox to the end-user.  If dialogResult = YES then progressBar is displayed and is started (0 to 100 step 10) and after the progressBar is finished, I want to show the end-user another messageBox.  

My situation currently however, is when the end-user clicks YES - both the progressBar and the next messageBox are displayed at the same time.  Which cause a big proplem since the end-user can click the YES/NO of the second messageBox even though the progressBar isn't finished.

mb
Avatar of vigrid
vigrid

Use ShowDialog method for the progress bar instead of Show method. HTH
Avatar of mebjen

ASKER

ShowDialog doesn't make any difference
Can you paste your source code here?
If the code updating the progress bar is in a seperate thread, then in the first thread before displaying the second message box, do 1 second thread sleeps in a loop until the second thread completes.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think

if you want second dialog show after progressbar end it may be

if DialogResult.Yes=MessageBox.Show("the first") then
  progressBar.Visible=true;
  //doing somthing and change the progressbar
  MEssageBox.Show("the second")
end if

if you want second dialog show with progressbar and it is a dialog designed by yourself it may be

if DialogResult.Yes=MessageBox.Show("the first") then
  progressBar.Visible=true;
  dim SecondDialog as frmSecond=new frmSecond
  SecondDialog.OKBtn.Enabled=false;
  SecondDialog.CancelBtn.Enabled=false;
  SecondDialog.Show();
  //doing somthing and change the progressbar
  SecondDialog.OKBtn.Enabled=true;
  SecondDialog.CancelBtn.Enabled=true;
end if
if you want to suspend any work until a thread completes...
use Thread.Join()  
(This will finish only when the thread completes)
Cheers...
Avatar of mebjen

ASKER

idle_Mind,

Thanks - thats exactly what I needed.


mb