I have a process that runs in my application and I'd like to be able to interrupt it so that I can view a form which contains relevant information and is normally minimised. It's easy enough to interrupt the process, but not easy to get it to start again at the place it was interrupted. It seems that Thread.Suspend is now obsolete and doesn't get evaluated.
I found this thread http://www.xtremedotnettalk.com/showthread.php?t=96994&highlight=suspend+thread but that only seems to anticipate interrupting the process each time it gets to the end. I want to be able to interrupt it in the middle and then continue where I left off. Can this be done?
Here's some code that may explain better what I'm trying to do:
I found this thread http://www.xtremedotnettalk.com/showthread.php?t=96994&highlight=suspend+thread but that only seems to anticipate interrupting the process each time it gets to the end. I want to be able to interrupt it in the middle and then continue where I left off. Can this be done?
Here's some code that may explain better what I'm trying to do:
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.WindowState = FormWindowState.Minimized
Count()
End Sub
Dim g As Integer
Dim q As Integer
Private Sub Count()
Do
g = g + 1
Me.Text = g
If Wait(1000) Then Exit Sub
'I'd like to be able to restart at this point, not the beginning.
q = q + 2
Me.Text = q
If Wait(500) Then Exit Sub
System.Windows.Forms.Application.DoEvents()
Loop
End Sub
Private Function Wait(ByVal t As Integer) As Boolean
System.Threading.Thread.Sleep(t)
If Me.WindowState <> FormWindowState.Minimized Then Return True
End Function
Private Sub cmdContinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdContinue.Click
Me.WindowState = FormWindowState.Minimized
Count()
End Sub
End Class