public static ThreadPoolBoundHandle BindHandle(SafeHandle handle) { if (handle == null) { throw new ArgumentNullException("handle"); } if (handle.IsClosed || handle.IsInvalid) { throw new ArgumentException("Invalid Handle", "handle"); } try { ThreadPool.BindHandle(handle); } catch (Exception expr_38) { if (expr_38.HResult == -2147024890) { throw new ArgumentException("Invalid Handle", "handle"); } if (expr_38.HResult == -2147024809) { throw new ArgumentException("Already Bound", "handle"); } throw; } return(new ThreadPoolBoundHandle(handle)); }
private static ThreadPoolBoundHandle BindHandleCore(SafeHandle handle) { Debug.Assert(handle != null); Debug.Assert(!handle.IsClosed); Debug.Assert(!handle.IsInvalid); try { // ThreadPool.BindHandle will always return true, otherwise, it throws. See the underlying FCall // implementation in ThreadPoolNative::CorBindIoCompletionCallback to see the implementation. bool succeeded = ThreadPool.BindHandle(handle); Debug.Assert(succeeded); } catch (Exception ex) { // BindHandle throws ApplicationException on full CLR and Exception on CoreCLR. // We do not let either of these leak and convert them to ArgumentException to // indicate that the specified handles are invalid. if (ex.HResult == System.HResults.E_HANDLE) // Bad handle { throw new ArgumentException(SR.Argument_InvalidHandle, nameof(handle)); } if (ex.HResult == System.HResults.E_INVALIDARG) // Handle already bound or sync handle { throw new ArgumentException(SR.Argument_AlreadyBoundOrSyncHandle, nameof(handle)); } throw; } return(new ThreadPoolBoundHandle(handle)); }
public static ThreadPoolBoundHandle BindHandle(SafeHandle handle) { if (handle == null) { throw new ArgumentNullException("handle"); } if (handle.IsClosed || handle.IsInvalid) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"), "handle"); } try { bool flag = ThreadPool.BindHandle(handle); } catch (Exception ex) { if (ex.HResult == -2147024890) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"), "handle"); } if (ex.HResult == -2147024809) { throw new ArgumentException(Environment.GetResourceString("Argument_AlreadyBoundOrSyncHandle"), "handle"); } throw; } return(new ThreadPoolBoundHandle(handle)); }
public static ThreadPoolBoundHandle BindHandle(SafeHandle handle) { if (handle == null) { throw new ArgumentNullException(nameof(handle)); } if (handle.IsClosed || handle.IsInvalid) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"), nameof(handle)); } try { // ThreadPool.BindHandle will always return true, otherwise, it throws. See the underlying FCall // implementation in ThreadPoolNative::CorBindIoCompletionCallback to see the implementation. bool succeeded = ThreadPool.BindHandle(handle); BCLDebug.Assert(succeeded, "Expected success"); } catch (Exception ex) { // BindHandle throws ApplicationException on full CLR and Exception on CoreCLR. // We do not let either of these leak and convert them to ArgumentException to // indicate that the specified handles are invalid. if (ex.HResult == E_HANDLE) // Bad handle { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"), nameof(handle)); } if (ex.HResult == E_INVALIDARG) // Handle already bound or sync handle { throw new ArgumentException(Environment.GetResourceString("Argument_AlreadyBoundOrSyncHandle"), nameof(handle)); } throw; } return(new ThreadPoolBoundHandle(handle)); }