System.Net.Http.WinHttpRequestState.Pin C# (CSharp) Method

Pin() public method

public Pin ( ) : void
return void
        public void Pin()
        {
            if (!_operationHandle.IsAllocated)
            {
#if DEBUG
                Interlocked.Increment(ref s_dbg_pin);
#endif
                _operationHandle = GCHandle.Alloc(this);
            }
        }

Usage Example

Example #1
0
        private RendezvousAwaitable<int> InternalSendRequestAsync(WinHttpRequestState state)
        {
            lock (state.Lock)
            {
                state.Pin();
                if (!Interop.WinHttp.WinHttpSendRequest(
                    state.RequestHandle,
                    null,
                    0,
                    IntPtr.Zero,
                    0,
                    0,
                    state.ToIntPtr()))
                {
                    // Dispose (which will unpin) the state object. Since this failed, WinHTTP won't associate
                    // our context value (state object) to the request handle. And thus we won't get HANDLE_CLOSING
                    // notifications which would normally cause the state object to be unpinned and disposed.
                    state.Dispose();
                    WinHttpException.ThrowExceptionUsingLastError();
                }
            }

            return state.LifecycleAwaitable;
        }
All Usage Examples Of System.Net.Http.WinHttpRequestState::Pin