public void Connect(IPEndPoint endpoint, TcpSocketConnectCallback callback) { TcpSocketConnectRoutine routine = new TcpSocketConnectRoutine(handle, worker, endpoint); TcpSocketConnectResult result = new TcpSocketConnectResult { Handle = handle, Socket = this, Endpoint = endpoint, OnConnected = callback }; routine.Execute(result); }
public Task <TcpSocketConnect> Connect(IPEndPoint endpoint) { TcpSocketConnectResult result = new TcpSocketConnectResult { Socket = this, Handle = handle, Endpoint = endpoint, Event = new ManualResetEvent(false) }; TcpSocketConnectRoutine routine = new TcpSocketConnectRoutine(handle, worker, endpoint); Task <TcpSocketConnect> task = Task.Factory.FromAsync(result, result.Unpack); routine.Execute(result); return(task); }