private void Dispose(bool disposing)
{
#if DEBUG
Interlocked.Increment(ref s_dbg_callDispose);
#endif
if (WinHttpTraceHelper.IsTraceEnabled())
{
WinHttpTraceHelper.Trace(
"WinHttpRequestState.Dispose, GCHandle=0x{0:X}, disposed={1}, disposing={2}",
ToIntPtr(),
_disposed,
disposing);
}
// Since there is no finalizer and this class is sealed, the disposing parameter should be TRUE.
Debug.Assert(disposing, "WinHttpRequestState.Dispose() should have disposing=TRUE");
if (_disposed)
{
return;
}
_disposed = true;
if (_operationHandle.IsAllocated)
{
// This method only gets called when the WinHTTP request handle is fully closed and thus all
// async operations are done. So, it is safe at this point to unpin the buffers and release
// the strong GCHandle for this object.
if (_cachedReceivePinnedBuffer.IsAllocated)
{
_cachedReceivePinnedBuffer.Free();
_cachedReceivePinnedBuffer = default(GCHandle);
}
#if DEBUG
Interlocked.Increment(ref s_dbg_operationHandleFree);
#endif
_operationHandle.Free();
_operationHandle = default(GCHandle);
}
}