I have an application which is taking ages to close. When I close the app, it tries to dispose a number of threads that do TCP scanning, WCF P2P attempts, and so on. The problem lies in a WCF thread that stalls on a method for about 17 seconds.
IP2PAuthenticationService server;
ChannelFactory<IP2PAuthenticationService> channelFactory;
channelFactory = new ChannelFactory<IP2PAuthenticationService>(binding, endpointAddress);
server = channelFactory.CreateChannel();
string result = server.SendMyDetails(myContract, "foo");
So all this happens inside a thread. When the form closes it attempts to dispose the thread
if (prospectCrawlerThread != null)
{
prospectCrawlerThread.Abort();
//prospectCrawlerThread.Join();
prospectCrawlerThread = null;
}
I've confirmed this by uncommenting the .Join(), and also by pausing the debug and seeing the threads that are still running.
What's the best way to get rid of this thread?
Edit: setting the thread to background seemed to make it quicker
prospectCrawlerThread.IsBackground = true;