Esempio n. 1
0
        // The only way to abort pending async operations in WinHTTP is to close the request handle.
        // This causes WinHTTP to cancel any pending I/O and accelerating its callbacks on the handle.
        // This causes our related TaskCompletionSource objects to move to a terminal state.
        //
        // We only want to dispose the handle if we are actually waiting for a pending WinHTTP I/O to complete,
        // meaning that we are await'ing for a Task to complete. While we could simply call dispose without
        // a pending operation, it would cause random failures in the other threads when we expect a valid handle.
        private void CancelPendingResponseStreamReadOperation()
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(this);
            }
            lock (_state.Lock)
            {
                if (_state.AsyncReadInProgress)
                {
                    if (NetEventSource.IsEnabled)
                    {
                        NetEventSource.Info("before dispose");
                    }
                    _requestHandle?.Dispose(); // null check necessary to handle race condition between stream disposal and cancellation
                    if (NetEventSource.IsEnabled)
                    {
                        NetEventSource.Info("after dispose");
                    }
                }
            }

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Exit(this);
            }
        }
Esempio n. 2
0
        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                _disposed = true;

                // TODO (Issue 2508): Pinned buffers must be released in the callback, when it is guaranteed no further
                // operations will be made to the send/receive buffers.
                if (_cachedReceivePinnedBuffer.IsAllocated)
                {
                    _cachedReceivePinnedBuffer.Free();
                    _cachedReceivePinnedBuffer = default(GCHandle);
                }

                if (disposing)
                {
                    if (_requestHandle != null)
                    {
                        _requestHandle.Dispose();
                        _requestHandle = null;
                    }
                }
            }

            base.Dispose(disposing);
        }
        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                _disposed = true;

                if (disposing)
                {
                    if (_requestHandle != null)
                    {
                        _requestHandle.Dispose();
                        _requestHandle = null;
                    }
                }
            }

            base.Dispose(disposing);
        }
 // The only way to abort pending async operations in WinHTTP is to close the request handle.
 // This causes WinHTTP to cancel any pending I/O and accelerating its callbacks on the handle.
 // This causes our related TaskCompletionSource objects to move to a terminal state.
 //
 // We only want to dispose the handle if we are actually waiting for a pending WinHTTP I/O to complete,
 // meaning that we are await'ing for a Task to complete. While we could simply call dispose without
 // a pending operation, it would cause random failures in the other threads when we expect a valid handle.
 private void CancelPendingResponseStreamReadOperation()
 {
     WinHttpTraceHelper.Trace("WinHttpResponseStream.CancelPendingResponseStreamReadOperation");
     lock (_state.Lock)
     {
         if (_state.AsyncReadInProgress)
         {
             WinHttpTraceHelper.Trace("WinHttpResponseStream.CancelPendingResponseStreamReadOperation: before dispose");
             _requestHandle?.Dispose(); // null check necessary to handle race condition between stream disposal and cancellation
             WinHttpTraceHelper.Trace("WinHttpResponseStream.CancelPendingResponseStreamReadOperation: after dispose");
         }
     }
 }