Terminating a thread from the main thread

  • Thread starter Charles A. Lackman
  • 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
 
C

Cor Ligthert

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
 
H

Herfried K. Wagner [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top