public static unsafe ThreadPoolBoundHandle BindHandle(SafeHandle handle) { if (handle == null) { throw new ArgumentNullException(nameof(handle)); } if (handle.IsClosed || handle.IsInvalid) { throw new ArgumentException(SR.Argument_InvalidHandle, nameof(handle)); } SafeThreadPoolIOHandle threadPoolHandle = Interop.Kernel32.CreateThreadpoolIo(handle, &OnNativeIOCompleted, IntPtr.Zero, IntPtr.Zero); if (threadPoolHandle.IsInvalid) { int errorCode = Marshal.GetLastWin32Error(); if (errorCode == Interop.Errors.ERROR_INVALID_HANDLE) // Bad handle { throw new ArgumentException(SR.Argument_InvalidHandle, nameof(handle)); } if (errorCode == Interop.Errors.ERROR_INVALID_PARAMETER) // Handle already bound or sync handle { throw new ArgumentException(SR.Argument_AlreadyBoundOrSyncHandle, nameof(handle)); } throw Win32Marshal.GetExceptionForWin32Error(errorCode); } return(new ThreadPoolBoundHandle(handle, threadPoolHandle)); }
public static ThreadPoolBoundHandle BindHandle(SafeHandle handle) { if (handle == null) { throw new ArgumentNullException(nameof(handle)); } if (handle.IsClosed || handle.IsInvalid) { throw new ArgumentException(SR.Argument_InvalidHandle, nameof(handle)); } IntPtr callback = AddrofIntrinsics.AddrOf <Interop.NativeIoCompletionCallback>(OnNativeIOCompleted); SafeThreadPoolIOHandle threadPoolHandle = Interop.mincore.CreateThreadpoolIo(handle, callback, IntPtr.Zero, IntPtr.Zero); if (threadPoolHandle.IsInvalid) { int errorCode = Marshal.GetLastWin32Error(); if (errorCode == Interop.Errors.ERROR_INVALID_HANDLE) // Bad handle { throw new ArgumentException(SR.Argument_InvalidHandle, nameof(handle)); } if (errorCode == Interop.Errors.ERROR_INVALID_PARAMETER) // Handle already bound or sync handle { throw new ArgumentException(SR.Argument_AlreadyBoundOrSyncHandle, nameof(handle)); } throw Win32Marshal.GetExceptionForWin32Error(errorCode); } return(new ThreadPoolBoundHandle(handle, threadPoolHandle)); }
public static ThreadPoolBoundHandle BindHandle(SafeHandle handle) { if (handle == null) { throw new ArgumentNullException("handle"); } if (handle.IsClosed || handle.IsInvalid) { throw new ArgumentException(SR.Argument_InvalidHandle, "handle"); } // Make sure we use a statically-rooted completion callback, // so it doesn't get collected while the I/O is in progress. Interop.NativeIoCompletionCallback callback = s_nativeIoCompletionCallback; if (callback == null) { s_nativeIoCompletionCallback = callback = new Interop.NativeIoCompletionCallback(OnNativeIOCompleted); } SafeThreadPoolIOHandle threadPoolHandle = Interop.mincore.CreateThreadpoolIo(handle, s_nativeIoCompletionCallback, IntPtr.Zero, IntPtr.Zero); if (threadPoolHandle.IsInvalid) { int hr = Marshal.GetHRForLastWin32Error(); if (hr == System.HResults.E_HANDLE) // Bad handle { throw new ArgumentException(SR.Argument_InvalidHandle, "handle"); } if (hr == System.HResults.E_INVALIDARG) // Handle already bound or sync handle { throw new ArgumentException(SR.Argument_AlreadyBoundOrSyncHandle, "handle"); } throw Marshal.GetExceptionForHR(hr); } return(new ThreadPoolBoundHandle(handle, threadPoolHandle)); }
private ThreadPoolBoundHandle(SafeHandle handle, SafeThreadPoolIOHandle threadPoolHandle) { _threadPoolHandle = threadPoolHandle; _handle = handle; }
internal static unsafe partial void CancelThreadpoolIo(SafeThreadPoolIOHandle pio);
internal static extern unsafe void CancelThreadpoolIo(SafeThreadPoolIOHandle pio);
internal static extern unsafe void StartThreadpoolIo(SafeThreadPoolIOHandle pio);