Hi,
"spammy" <me@privacy.net> wrote in message
news:2g**********@uni-berlin.de...
"Bob Rock" <no***************************@hotmail.com> wrote in message
news:en****************@TK2MSFTNGP11.phx.gbl... You could throw an exception that is only caught in the main method of the your thread, then just return.
Probably a stupid question, but, how do you throw and exception from a
thread (the main thread) that needs to be caught by another thread (the
worker thread)????
could Thread.Interrupt() do that?
Yes.
Interrupt called on a certain Thread object, will throw an exception on the
actual thread that the object represents, on the next wait, sleep or join
operation performed on that thread, or if the thread is already waiting,
joining or sleeping (WaitHandle::Waitxxx, Thread::Sleep, Thread::Join). The
exception is of type ThreadInterruptedException.
Abort called on a certain Thread object, will throw an exception on the
actual thread that the object represents, period. The exception is of type
ThreadAbortedException. There is one exception (no pun). The framework
cannot throw the exception if the thread is executing interop code (i.c. it
can only be thrown from managed code).
It does not matter from which thread or on what Thread object you call Abort
or Interrupt, so you can call these methods on the current thread being
executed. Calling Thread.Abort from the current thread will surely throw a
ThreadAbortedException. You can easily verify, just execute the following on
a thread:
Thread.CurrentThread.Abort();
Add a catch handler for the exception, you will see.
Cheers,
---
Tom Tempelaere