private void FinishReceiving(bool success) { if (trace.IsEnabled()) { trace.ReceiveStop(name, IsAlive, success); } var callback = (Action <bool>)recvArgs.UserToken; IsBusy = false; callback(success); }
private void ReceiveAsyncCompleted(object sender, SocketAsyncEventArgs recvArgs) { var received = recvArgs.BytesTransferred; CoreEventSource.ReceiveChunk(name, IsAlive, received, recvArgs.SocketError); var success = recvArgs.SocketError == SocketError.Success && received > 0; recvBuffer.SetDataLength(success ? received : 0); CoreEventSource.ReceiveStop(name, IsAlive, success); Volatile.Write(ref isReceiving, 0); ((Action <bool>)recvArgs.UserToken).Invoke(success); }