Hello, eejit,
Re:
but do I have to create a seperate thread to handle a click event to
restart it?
Yes. And that will be too much trouble for what you are trying to do.
An approach similar to what Josef is suggesting is probably best for
your case.
But If you just want to wait for the user to push a button before
continuing, you really don't need a fixed time-out period (or even to
use the Sleep method). Here is another example, from a form with a
label and two buttons labeled "Run" and "Resume".
' This is a "member" variable (like Josef suggests).
Private mbooResumed As Boolean = False
Private Sub cmdRun_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles cmdRun.Click
' This button click starts a long "process".
mbooResumed = False
cmdRun.Enabled = False
' This is a "long" process that gets paused.
For intCount As Integer = 1 To 2000
Label1.Text = intCount
Application.DoEvents()
If (intCount = 1000) Then
WaitForResume()
End If
Next intCount
cmdRun.Enabled = True
End Sub
Private Sub cmdResume_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles cmdResume.Click
' This button click resumes the paused "process".
mbooResumed = True
End Sub
Sub WaitForResume()
' This routine pauses the "process".
While (Not mbooResumed)
Application.DoEvents()
' Using Sleep here is possible, but not required.
'Thread.Sleep(100)
End While
End Sub
I guess that using Sleep will reduce the load that your application
places on the system while it waits, but I would use a short sleep
interval (<=200 msec) to reduce latency after the user pushes the button.
Cheers,
Randy