Solved

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

Posted on 2004-09-20
8
215 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now