Solved

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

Posted on 2006-07-23
2
272 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
[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
2 Comments
 
LVL 86

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

724 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