App hangs for 20 secs on exit after TcpClient BeginConnect
I have problem with strange behavior of TcpClient.BeginConnect() and TcpClient.EndConnect() methods. I use BeginConnect() to add timeout to Connect() method (see extension method code below). If I get connected I call EndConnect() and every thing is ok, but If I get timeout I can't call EndConnect() because it will block for about 20 seconds, so I just call this non-blocking code: result.AsyncWaitHandle.Close(); result.AsyncWaitHandle.Dispose(); client.Close(); Problem is when I close the form right after getting timeout (after running above code) my app will "hang" for about 20 seconds. Is