private void ConnectCallback(IAsyncResult ar) { // Retrieve the callback from the state object. OnConnect onConnect = (OnConnect)ar.AsyncState; try { // Complete the connection. sock.EndConnect(ar); LogUtil.DebugFormat("ClientSocket.ConnectCallback: connected to {0}", sock.RemoteEndPoint.ToString()); onConnect.Invoke(true); } catch (Exception e) { LogUtil.Error("ClientSocket.ConnectCallback: " + e.ToString()); onConnect.Invoke(false); } }