Can resource of system be disposed when a thread is aborted?

  • Thread starter Thread starter fjlpf
  • Start date Start date
F

fjlpf

I create a new thread, and in it, create a socket.

Now I want to terminate the thread in main thread, but

can the socket be disposed automaticly?

If it can't, how can I manage this situation?

Thanks in advance!
 
Hi,

Yes, it can.
Add a try/catch handler to your thread, i.e:

Init socket
try
{
...
}
catch (ThreadAbortException ex)
{
// dispose here
}
 
Back
Top