Exemple #1
0
        public unsafe void FreeNativeOverlapped(NativeOverlapped *overlapped)
        {
            if (overlapped == null)
            {
                throw new ArgumentNullException(nameof(overlapped));
            }

            Win32ThreadPoolNativeOverlapped *threadPoolOverlapped = Win32ThreadPoolNativeOverlapped.FromNativeOverlapped(overlapped);

            Win32ThreadPoolNativeOverlapped.OverlappedData data = GetOverlappedData(threadPoolOverlapped, this);

            if (!data._completed)
            {
                Interop.mincore.CancelThreadpoolIo(_threadPoolHandle);
                Release();
            }

            data._boundHandle = null;
            data._completed   = false;

            if (data._preAllocated != null)
            {
                data._preAllocated.Release();
            }
            else
            {
                Win32ThreadPoolNativeOverlapped.Free(threadPoolOverlapped);
            }
        }
Exemple #2
0
 unsafe void IDeferredDisposable.OnFinalRelease(bool disposed)
 {
     if (_overlapped != null)
     {
         if (disposed)
         {
             Win32ThreadPoolNativeOverlapped.Free(_overlapped);
         }
         else
         {
             *Win32ThreadPoolNativeOverlapped.ToNativeOverlapped(_overlapped) = default(NativeOverlapped);
         }
     }
 }