Solved

How to stop program when I'm using Thread.Sleep and ProgressBar and recording from Microphone.

Posted on 2006-07-23
2
258 Views
Last Modified: 2010-04-23
First, thank Chaosian for your solution you gave me:    http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21927683.html, It's ok when i use only my RecordFeature.
But:

I'm trying to do:  Run a progressBar in a constant length of time: ex: 5000 ms
                         Record from Mic when a progressbar is running.
                         
Here is my code:      

Record() 'Start recording
' Start running progressBar
  PreBar.value = 0
 While PreBar.value < 100
  PreBar.value += 1
  PreBar.Refresh()
  System.Threading.Thread.Sleep(50)
 End While
StopRecord()  ' Stop Recording from mic and progressbar is over

It works well.

Because of the   thread.sleep  I Can't control any buttons in my form when progressbar running. If I want to finish immediately by pushing a button ( don't want to record anymore when progressbar is running ) What should  I do ???

With this request in my project, I'm trying to use timer to running progressbar but any way I still have thread.sleep.
I also use mutilthread but it has a lot of errors.
could you give me a good solution or give me some advice  to do my request ???

Thanks



0
Comment
Question by:cutoi
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17165617
You can't press your button because the code is stuck inside the While...Wend loop.

You need to add a call to DoEvents() inside your loop:

    While PreBar.value < 100
        PreBar.value += 1
        PreBar.Refresh()
        System.Threading.Thread.Sleep(50)
        Application.DoEvents()
    End While

...but you ALSO need to add a way for the loop to drop out when the cancel button is pressed:

    Private Cancelled As Boolean = False

    Private Sub btnCancel_Click(...) Handles btnCancel.Click
        Cancelled = True
    End Sub

    ...
        Cancelled = False
        While Not Cancelled AndAlso PreBar.value < 100
            PreBar.value += 1
            PreBar.Refresh()
            System.Threading.Thread.Sleep(50)
            Application.DoEvents()
        End While
0
 

Author Comment

by:cutoi
ID: 17166654
Really Wonderful ! I tried many complex solution but It couldn't work.
Thank you IdleMind , You're  an ExcellentExpert.
I'm very glad that I have a good solution with ease.

Thanks IdleMind again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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