Look at post #5 for the updated code. :D
Printable View
Look at post #5 for the updated code. :D
This is nice. This will help a lot on the future..
What exactly is the point of the demonstration? There's no pausing whatsoever - you can put 10 on the label instantly, or you can freeze the application. Yay.
Can you please explain more about the demonstration? What does it do, exactly? Am I not pressing the buttons in the right order?
Minitech, As this post is from Nov 19th, 2010 I have no idea what's wrong with code.Quote:
Originally Posted by minitech
It must of worked because if it did not, I would of never posted the code.
I will upload another explain as soon as my replacement SSD will come back.
I lost VS2010 Pro, and all my other stuff when it failed.
Maybe by next Tuesday or Wednesday I will update the code.
RMA takes forever. :bigyello:
But, when you tried this code:
Does the Label text still count up even after you pressed Button1_Click?Code:Imports System.Threading
Public Class Form1
Private Pause As New ManualResetEvent(True)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Pause.Reset() ' Pause the code
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Pause.Set() 'Remove the lock
End Sub
Dim i As Integer
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Pause.WaitOne()
Do Until i = 10
i = i + 1
Label1.Text = i
Loop
End Sub
Try pressing 3, 1, 2.
3) Starts the code.
1) Puts a lock on it.
2) Removes the lock.
I have updated the code.
I did provided minimum comments inside the code but it should not be that hard to understand.
Use the diagram below to name the elements correctly.
If you have any questions then ask them.
vb.net Code:
Imports System.Threading Public Class Form1 Private NewThread As Thread Private Pause As New ManualResetEvent(True) Dim Desideratum_Integer As Integer = 10000 Dim i As Integer Private Sub SubThread() Try Do Until i = 10000 Pause.WaitOne() i = i + 1 lblProgress.Text = "Number Count: " & i & " out of: " & Desideratum_Integer lblPrecent.Text = i / Desideratum_Integer * 100 & " %" ProgressBar1.Value = i Loop lblProgress.Text = "Number Count: " & i & " out of: " & Desideratum_Integer lblPrecent.Text = i / Desideratum_Integer * 100 & " %" Count_Up.Text = "Start" i = 0 ProgressBar1.Value = 0 Curr.Text = "Current Task: Done!" Catch End Try End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load CheckForIllegalCrossThreadCalls = False ProgressBar1.Maximum = 10000 End Sub Private Sub Count_Up_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Count_Up.Click NewThread = New Thread(AddressOf SubThread) NewThread.IsBackground = True NewThread.Start() Curr.Text = "Current Task: Calculating." If Count_Up.Text = "Pause" Then Pause.Reset() ' Pause the code Count_Up.Text = "Resume" Curr.Text = "Current Task: Paused." ElseIf Count_Up.Text = "Resume" Then Pause.Set() 'Remove the lock Count_Up.Text = "Pause" Curr.Text = "Current Task: Calculating." ElseIf Count_Up.Text = "Start" Then Count_Up.Text = "Pause" End If End Sub End Class