Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-09-20
8
Medium Priority
?
229 Views
Last Modified: 2010-04-17
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
0
Comment
Question by:mebjen
8 Comments
 
LVL 4

Expert Comment

by:vigrid
ID: 12107756
Use ShowDialog method for the progress bar instead of Show method. HTH
0
 

Author Comment

by:mebjen
ID: 12107836
ShowDialog doesn't make any difference
0
 
LVL 4

Expert Comment

by:vigrid
ID: 12107882
Can you paste your source code here?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:cookre
ID: 12108444
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.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 12108898
>> How do I suspend the current Thread until progressBar is finished??

Use the Join() method of the thread that is doing the work:

    Private t As Thread
   
    Public Sub foo()
        t = New Thread(AddressOf Me.startRecursing)
        t.Start()
        t.Join() ' Code will stop here until thread "t" is done     <------------------ Join thread
        If MessageBox.Show("Install Spyware?", "Highly Recommended", MessageBoxButtons.YesNo) = DialogResult.Yes Then
            ' Install Spyware at users request
        Else
            ' Install Spyware anyway...
        End If
    End Sub

    Private Sub startRecursing()
        ' some process that runs in a different thread
        ' and updates your progressbar
    End Sub

Regards,

Idle_Mind
0
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12110200
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
0
 
LVL 8

Expert Comment

by:rajaloysious
ID: 12110412
if you want to suspend any work until a thread completes...
use Thread.Join()  
(This will finish only when the thread completes)
Cheers...
0
 

Author Comment

by:mebjen
ID: 12110968
idle_Mind,

Thanks - thats exactly what I needed.


mb
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Six Sigma Control Plans

926 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