Hello all,
I am trying to find a way to resume a thread after catching the AbortThreadException and calling AbortReset.
My thread is running a loop to control two motors used in a raster scan. Once the button is pressed to begin the scan, I want to be able to click a stop scan button and have the following happen:
1. AbortThreadException is thrown and caught- a window comes up asking if you really want to abort the scan. Click yes for abort, no for suspend, or cancel to continue scanning.
2. Given users answer the program responds accordingly- If cancel, then the scan should continue right where it left off and not restart.
My problem occurs in my understanding of the thread events. I am not sure how to tell a thread to wait for a button event nor do i know how to tell a thread to continue where it left off. I also noticed that the 'suspend' and 'resume' methods have been deemed obsolete and i am not sure of the alternative way of doing those actions.
The following is the code used to catch the exception and execute the task.
Any help or insight is much appreciated!
Thanks,
IHIguy
I am trying to find a way to resume a thread after catching the AbortThreadException and calling AbortReset.
My thread is running a loop to control two motors used in a raster scan. Once the button is pressed to begin the scan, I want to be able to click a stop scan button and have the following happen:
1. AbortThreadException is thrown and caught- a window comes up asking if you really want to abort the scan. Click yes for abort, no for suspend, or cancel to continue scanning.
2. Given users answer the program responds accordingly- If cancel, then the scan should continue right where it left off and not restart.
My problem occurs in my understanding of the thread events. I am not sure how to tell a thread to wait for a button event nor do i know how to tell a thread to continue where it left off. I also noticed that the 'suspend' and 'resume' methods have been deemed obsolete and i am not sure of the alternative way of doing those actions.
The following is the code used to catch the exception and execute the task.
VB.NET:
Private Sub RasterScan()
Try
'My control loop for the two motors is here.
' It is a For Next loop that scans and increments the two motors used for the scan.
Catch e As ThreadAbortException
Dim Result As Integer
Result = MessageBox.Show("Scan stopped. Do you want to abort the scan?" & vbNewLine & _
"Click 'Yes' to abort, 'No' to Pause the scan or 'Cancel' to resume scanning." _
, "Scan Stopped", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
Select Case Result
Case 6 'Yes
MoveTo.Abort()
Case 7 'No
'This should pause the scan and resume only when the user clicks a resume scan button.
'It should resume from where it left off.
Case Else ' Cancel
'This should continue the scan where it left off- not start from the beginning.
End Select
End Try
MessageBox.Show("Scan Complete", "Successful Scan")
BeginScanButton.Invoke(Sub() BeginScanButton.Text = "Begin Scan")
Thread.CurrentThread.Abort()
End Sub
Any help or insight is much appreciated!
Thanks,
IHIguy