System.Net.Http.WinHttpException.CreateExceptionUsingLastError C# (CSharp) Method

CreateExceptionUsingLastError() public static method

public static CreateExceptionUsingLastError ( ) : WinHttpException
return WinHttpException
        public static WinHttpException CreateExceptionUsingLastError()
        {
            int lastError = Marshal.GetLastWin32Error();
            return CreateExceptionUsingError(lastError);
        }

Usage Example

Esempio n. 1
0
        private async Task <int> ReadAsyncCore(byte[] buffer, int offset, int count, CancellationToken token)
        {
            if (count == 0)
            {
                return(0);
            }

            _state.PinReceiveBuffer(buffer);
            var ctr = token.Register(s => ((WinHttpResponseStream)s).CancelPendingResponseStreamReadOperation(), this);

            _state.AsyncReadInProgress = true;
            try
            {
                lock (_state.Lock)
                {
                    Debug.Assert(!_requestHandle.IsInvalid);
                    if (!Interop.WinHttp.WinHttpQueryDataAvailable(_requestHandle, IntPtr.Zero))
                    {
                        throw new IOException(SR.net_http_io_read, WinHttpException.CreateExceptionUsingLastError(nameof(Interop.WinHttp.WinHttpQueryDataAvailable)));
                    }
                }

                int bytesAvailable = await _state.LifecycleAwaitable;

                lock (_state.Lock)
                {
                    Debug.Assert(!_requestHandle.IsInvalid);
                    if (!Interop.WinHttp.WinHttpReadData(
                            _requestHandle,
                            Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset),
                            (uint)Math.Min(bytesAvailable, count),
                            IntPtr.Zero))
                    {
                        throw new IOException(SR.net_http_io_read, WinHttpException.CreateExceptionUsingLastError(nameof(Interop.WinHttp.WinHttpReadData)));
                    }
                }

                return(await _state.LifecycleAwaitable);
            }
            finally
            {
                _state.AsyncReadInProgress = false;
                ctr.Dispose();
            }
        }
All Usage Examples Of System.Net.Http.WinHttpException::CreateExceptionUsingLastError