public void connectCallback(IAsyncResult ar) { Socket sock = (Socket)ar.AsyncState; if (sock != null) { try { sock.EndConnect(ar); } catch (Exception e) { Console.Write(e.ToString() + "\n" + e.StackTrace); return; } } else { return; } timeoutEvent.Set(); }