Solved

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

Posted on 2006-07-23
2
264 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…

828 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