Initialize the thread, and assign the method to run in the thread
Private objTheThread1 As System.Threading.Thread
The start button was pressed
Private Sub btnStart1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart1.Click
If Not objTheThread1 Is Nothing Then
resume the thread if its running
If objTheThread1.ThreadState = Threading.ThreadState.Suspended Then
objTheThread1.Resume()
End If
Else
start the thread
Dim objThread As New System.Threading.Thread(AddressOf RunLoop1)
objTheThread1 = objThread
objThread.Start()
End If
End Sub
The pause button was pressed
Private Sub btnStop1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop1.Click
If Not objTheThread1 Is Nothing Then
If objTheThread1.IsAlive Then
objTheThread1.Suspend()
End If
End If
End Sub
Private Sub RunLoop1()
Dim i As Integer
i = 0
Do While i >= 0
i = i + 1
lblStatus1.Text = i.ToString
Application.DoEvents()
Loop
End Sub