private void SocketOnDataReceived(object sender, SocketReceivedDataEventArgs args) { if (_activeRequest == null) { return; } ISocket socket = (ISocket)sender; if (_activeRequest.OnResponseReceived(args)) { _lastResponse = _activeRequest.Response; _activeRequest = null; // If this was an async send, we saved a ref to the socket. Clean that up now. if (_socket != null && _socket == socket) { _socket.SocketClosed -= SocketOnSocketClosed; _socket.DataReceived -= SocketOnDataReceived; _socket.Dispose(); _socket = null; } _requestCompletedEvent.Set(); } }