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...
 

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

Back
Top