Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-09-20
8
Medium Priority
?
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression

688 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