"jmd.msdn" <jm******@newsg roup.nospam> wrote in message
news:eJ******** ******@TK2MSFTN GP09.phx.gbl...
Hello.
I want to abort a thread whose thread function contains something like :
void threadfunc ()
{
while ( 1 )
{
... some code
udpClient.Recei ve(...); // instance to read network
data
... some code using received data
}
}
Another method in my thread class has :
thread.Abort();
Problem when Abort() has been called : the thread, as seen in debug mode
shows :
1. do NOT abort
2. remains in an AbortRequested ThreadState
3. IsAlive is true
Question :
Does someone can tell me what can maintains a thread in an
AbortRequested ThreadState ?
Thank you.
jmd
1. Never call Thread.Abort, this method is only safe when you intend to
abandon the current Application domain, in which case it's not needed to
call Abort anyway because AppDomain.Unloa d calls Abort when it uloads the
offending domain.
2. When you need to end a thread function you should set an event or set a
status flag that you can check in your while loop.
But this won't solve your problem as it's related to the Receive call which
is suspended (waiting for data) in unmanaged code, all you can do is close
udpClient's underlying socket, this will force the Receive to end and give
you a chance to exit the loop.
Willy.