Solved

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

Posted on 2004-09-20
8
223 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 85

Accepted Solution

by:
Mike Tomlinson earned 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

820 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