Terminating a thread from the main thread

  • Thread starter Thread starter Charles A. Lackman
  • Start date Start date
C

Charles A. Lackman

Hello,

I have created a thread that writes data from a memorystream to the
harddrive. If the user, during the write decides to cancel the operation, I
call Abort on the thread.

i.e.

Private Sub WriteToDiskButton_Click
MyThread= New Threading.Thread(AddressOf WriteToDisk)
MyThread.Start()
End Sub

Private Sub WriteToDisk
Try
'do stuff
Catch Ex as System.Threading.ThreadAbortException
End Try
End Sub

Private Sub AbortButton_Click
MyThread.Abort
End Sub

When the Abort takes place I get two Abort Exceptions, I am able to catch
the fist one but how do I catch both exceptions so the user is not aware of
them.

Chuck
 
Charles,

I think it is better to fine out why the exception is throwed, that should
not happen with just an abortion of a thread.

A try and catch is for situations when you cannot find that.

By instance when you know that a file exist on a shared disk, however don't
know if it is in use already.

Just my thought,

Cor
 
Charles said:
Private Sub AbortButton_Click
MyThread.Abort
End Sub

When the Abort takes place I get two Abort Exceptions, I am able to catch
the fist one but how do I catch both exceptions so the user is not aware of
them.

Add a handler to 'System.Windows.Forms.Application.ThreadException' in
order to catch the exceptions.
 
Back
Top