Solved

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

Posted on 2004-09-20
8
220 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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