System.Threading.ThreadPoolBoundHandle.AllocateNativeOverlapped C# (CSharp) Метод

AllocateNativeOverlapped() приватный Метод

private AllocateNativeOverlapped ( PreAllocatedOverlapped preAllocated ) : NativeOverlapped*
preAllocated PreAllocatedOverlapped
Результат NativeOverlapped*
        public unsafe NativeOverlapped* AllocateNativeOverlapped(PreAllocatedOverlapped preAllocated)
        {
            if (preAllocated == null)
                throw new ArgumentNullException(nameof(preAllocated));

            bool addedRefToThis = false;
            bool addedRefToPreAllocated = false;
            try
            {
                addedRefToThis = AddRef();
                addedRefToPreAllocated = preAllocated.AddRef();

                Win32ThreadPoolNativeOverlapped.OverlappedData data = preAllocated._overlapped->Data;
                if (data._boundHandle != null)
                    throw new ArgumentException(SR.Argument_PreAllocatedAlreadyAllocated, nameof(preAllocated));

                data._boundHandle = this;

                Interop.Kernel32.StartThreadpoolIo(_threadPoolHandle);

                return Win32ThreadPoolNativeOverlapped.ToNativeOverlapped(preAllocated._overlapped);
            }
            catch
            {
                if (addedRefToPreAllocated)
                    preAllocated.Release();
                if (addedRefToThis)
                    Release();
                throw;
            }
        }

Same methods

ThreadPoolBoundHandle::AllocateNativeOverlapped ( IOCompletionCallback callback, object state, object pinData ) : NativeOverlapped*
ThreadPoolBoundHandle::AllocateNativeOverlapped ( System preAllocated ) : System.Threading.NativeOverlapped*
ThreadPoolBoundHandle::AllocateNativeOverlapped ( System callback, object state, object pinData ) : System.Threading.NativeOverlapped*

Usage Example

Пример #1
0
 private Interop.HttpApi.HTTP_REQUEST* Allocate(ThreadPoolBoundHandle boundHandle, uint size)
 {
     uint newSize = size != 0 ? size : RequestBuffer == null ? 4096 : Size;
     if (_nativeOverlapped != null && newSize != RequestBuffer.Length)
     {
         NativeOverlapped* nativeOverlapped = _nativeOverlapped;
         _nativeOverlapped = null;
         _boundHandle.FreeNativeOverlapped(nativeOverlapped);
     }
     if (_nativeOverlapped == null)
     {
         SetBuffer(checked((int)newSize));
         _boundHandle = boundHandle;
         _nativeOverlapped = boundHandle.AllocateNativeOverlapped(ListenerAsyncResult.IOCallback, state: _result, pinData: RequestBuffer);
         return (Interop.HttpApi.HTTP_REQUEST*)Marshal.UnsafeAddrOfPinnedArrayElement(RequestBuffer, 0);
     }
     return RequestBlob;
 }
All Usage Examples Of System.Threading.ThreadPoolBoundHandle::AllocateNativeOverlapped