G
Guest
First time with threads.
I have a simple but vexing problem.
There are two Win Forms FormA and FormB.
FormA is shown dialog on the main thread.
When the user clicks button1 on FormA a new workerthread is started if the
worker
thread is not alive.
If the worker thread is alive nothing happens.
The problem is when FormA is closed and FormB is alive I get an unhandled
exception at run time ... 'thread was being aborted'
In VS debugger the code works fine without errors.
The threadstart delegate looks like
Public Sub begin_formB()
dim newB as formB
Try
newB = New FormB
newB.ShowDialog()
newB.Dispose()
Catch e As ThreadAbortException
newB.close
newB.Dispose()
Finally
newB.close
newB.Dispose()
End Try
End Sub
The button1.click event handler looks like
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
' note tr is declared as a public thread variable in sub main
If tr.IsAlive Then Then Exit Sub
tr.Start()
End Sub
Sub main looks like
Public tr As New Thread(New ThreadStart(AddressOf results.begin_formB))
Sub Main()
My.Forms.FormA.ShowDialog()
If tr.IsAlive Then
tr.Abort()
tr.Join()
End If
End Sub
I can't understand why a runtime unhandled exception error of 'thread was
being aborted' .
I think my threadstart delegate is incorrect..
Any help?
Roger
I have a simple but vexing problem.
There are two Win Forms FormA and FormB.
FormA is shown dialog on the main thread.
When the user clicks button1 on FormA a new workerthread is started if the
worker
thread is not alive.
If the worker thread is alive nothing happens.
The problem is when FormA is closed and FormB is alive I get an unhandled
exception at run time ... 'thread was being aborted'
In VS debugger the code works fine without errors.
The threadstart delegate looks like
Public Sub begin_formB()
dim newB as formB
Try
newB = New FormB
newB.ShowDialog()
newB.Dispose()
Catch e As ThreadAbortException
newB.close
newB.Dispose()
Finally
newB.close
newB.Dispose()
End Try
End Sub
The button1.click event handler looks like
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
' note tr is declared as a public thread variable in sub main
If tr.IsAlive Then Then Exit Sub
tr.Start()
End Sub
Sub main looks like
Public tr As New Thread(New ThreadStart(AddressOf results.begin_formB))
Sub Main()
My.Forms.FormA.ShowDialog()
If tr.IsAlive Then
tr.Abort()
tr.Join()
End If
End Sub
I can't understand why a runtime unhandled exception error of 'thread was
being aborted' .
I think my threadstart delegate is incorrect..
Any help?
Roger