Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-07-23
2
Medium Priority
?
275 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 2000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

604 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