System.Net.HttpResponseStream.EndWrite C# (CSharp) Method

EndWrite() public method

public EndWrite ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult
return void
        public override void EndWrite(IAsyncResult asyncResult)
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(this);
                NetEventSource.Info(this, $"asyncResult:{asyncResult}");
            }
            if (asyncResult == null)
            {
                throw new ArgumentNullException(nameof(asyncResult));
            }
            HttpResponseStreamAsyncResult castedAsyncResult = asyncResult as HttpResponseStreamAsyncResult;
            if (castedAsyncResult == null || castedAsyncResult.AsyncObject != this)
            {
                throw new ArgumentException(SR.net_io_invalidasyncresult, nameof(asyncResult));
            }
            if (castedAsyncResult.EndCalled)
            {
                throw new InvalidOperationException(SR.Format(SR.net_io_invalidendcall, nameof(EndWrite)));
            }
            castedAsyncResult.EndCalled = true;
            // wait & then check for errors
            object returnValue = castedAsyncResult.InternalWaitForCompletion();

            Exception exception = returnValue as Exception;
            if (exception != null)
            {
                if (NetEventSource.IsEnabled) NetEventSource.Error(this, "Rethrowing exception:" + exception);
                _closed = true;
                _httpContext.Abort();
                throw exception;
            }

            if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
        }

Usage Example

Example #1
0
 private void NonBlockingCloseCallback(IAsyncResult asyncResult)
 {
     try {
         m_ResponseStream.EndWrite(asyncResult);
     }
     catch (Win32Exception) {
     }
     finally {
         m_ResponseStream.Close();
         HttpListenerContext.Close();
         m_ResponseState = ResponseState.Closed;
     }
 }