public void Disconnect(TcpSocketDisconnectCallback callback) { TcpSocketDisconnectRoutine routine = new TcpSocketDisconnectRoutine(handle); TcpSocketDisconnectResult result = new TcpSocketDisconnectResult { Handle = handle, Socket = this, OnDisconnected = callback }; routine.Execute(result); }
public Task <TcpSocketDisconnect> Disconnect() { TcpSocketDisconnectResult result = new TcpSocketDisconnectResult { Handle = handle, Socket = this, Event = new ManualResetEvent(false) }; Task <TcpSocketDisconnect> task = Task.Factory.FromAsync(result, ar => ((TcpSocketDisconnectResult)ar).CreateData()); TcpSocketDisconnectRoutine routine = new TcpSocketDisconnectRoutine(handle); routine.Execute(result); return(task); }