System.Net.WebSockets.WebSocketHttpListenerDuplexStream.OnCancel C# (CSharp) Method

OnCancel() private static method

private static OnCancel ( object state ) : void
state object
return void
        private static void OnCancel(object state)
        {
            Debug.Assert(state != null, "'state' MUST NOT be NULL.");
            WebSocketHttpListenerDuplexStream thisPtr = state as WebSocketHttpListenerDuplexStream;
            Debug.Assert(thisPtr != null, "'thisPtr' MUST NOT be NULL.");

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(state);
            }

            try
            {
                thisPtr._outputStream.SetClosedFlag();
                thisPtr._context.Abort();
            }
            catch { }

            TaskCompletionSource<int> readTaskCompletionSourceSnapshot = thisPtr._readTaskCompletionSource;

            if (readTaskCompletionSourceSnapshot != null)
            {
                readTaskCompletionSourceSnapshot.TrySetCanceled();
            }

            TaskCompletionSource<object> writeTaskCompletionSourceSnapshot = thisPtr._writeTaskCompletionSource;

            if (writeTaskCompletionSourceSnapshot != null)
            {
                writeTaskCompletionSourceSnapshot.TrySetCanceled();
            }

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Exit(state);
            }
        }