Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 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

19 Experts available now in Live!

Get 1:1 Help Now