David
Sun Oct 17 21:57:23 CDT 2004
"Richard Blewett [DevelopMentor]" <richardb@develop.com> wrote in message
news:O9Hd6jItEHA.2192@TK2MSFTNGP14.phx.gbl...
> Currently, in version 1.0 and 1.1 it is safe in two situations:
>
> 1) You may Abort the current thread (Thread.CurrentThread.Abort(); )
> 2) If you are taking down an AppDomain you can Abort all the threads
> running within that AppDomain
>
> Thats it.
>
Look at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/terminatethread.asp
I would add to your examples that it is safe to terminate a background
thread, when you know it's in a wait state.
EG
This thread
void threadProc()
{
while (!shutdown)
{
WaitForSingleObject(flarg,INFINITE);
... some short-running code
}
}
Can be safely aborted by this:
shutdown = true;
if (!backgroundThread.join(1000))
{
backgroundThread.abort();
}
Meaning you can safely abort background threads which you know to be in a
long wait, and which are coded to exit on an exception.
Now, if possible you should code a signal to abort the wait state, but
that's really neither here nor there. Sometimes it's appropriate to have a
long-running wait on some object, and if you have confidence that a
background thread is in that state, you can abort it if you need to.
David