Hello there,
Lets say I have something like this in my Mother Of All Threads:
Thread thread1 = new Thread(new ThreadStart(this.run));
thread1.Start();
//some unimportant code
thread1.Abort();
thread1.Join();
And in thread1 I have:
try {
tcpListener = new TcpListener(this.port);
tcpListener.Start();
tcpClient = tcpListener.AcceptTcpClient();
//more unimportant code
} catch (ThreadAbortException) {
tcpClient.Stop();
//not sure whether I need the line above, but that's not the problem
anyway
tcpListener.Stop();
}
What happens now is thread1 gets started, gets to the
"tcpListener.AcceptTcpClient()" call and waits for a client to connect.
In
the mean time Mother Of All Threads gets to the "thread1.Abort()" and
raises the ThreadAbortException... and nothing happens. tcpListener
still
hangs and waits for the connection, and blocks the ThreadAbortException
from occuring! Now, shouldn't that be impossible? I was taught to firmly
believe in the Almighty Exception... something's very wrong here...
would
somebody enlighten me, please!
BTW, yes, I know, I could make a socket which will connect to the server
and unblock the Listener, but that's a dirty and ugly hack. There should
be some elegant solution for interupting tcpListener... shouldn't it?