Abort thread within

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hi,
I have a loop running on a thread. When there is an error in the loop,
I'm trying to abort the thread. Is it possible to abort a thread
within a thread?
Thanks
 
Hi,
I have a loop running on a thread. When there is an error in the loop,
I'm trying to abort the thread. Is it possible to abort a thread
within a thread?
Thanks

Just leaving the function aborts the thread... What do you mean?

public void ThreadFunc()
{
try
{
while (mycondition)
{
// do stuff
}
}
catch ThreadAbortException
{
// do nothing?
}
catch (Exception ex)
{
// do your error trapping
}
finally
{
// do clean up if necessary
}

} // thread ends here....

If your attempting to abort your from your current thread, you can do:

Thread.CurrentThread.Abort();

This will cause an immediate ThreadAbortException to be thrown, and you'll
jump to your catch block...
 
Back
Top