private static InvalidOperationException CreateCannotGetResultsFromIncompleteOperationException(Exception cause) { InvalidOperationException ex = (cause == null) ? new InvalidOperationException(SR.InvalidOperation_CannotGetResultsFromIncompleteOperation) : new InvalidOperationException(SR.InvalidOperation_CannotGetResultsFromIncompleteOperation, cause); ex.SetHResult(E_ILLEGAL_METHOD_CALL); return(ex); }
/// <summary>Close the async info.</summary> public virtual void Close() { if (IsInClosedState) { return; } // Cannot Close from a non-terminal state: if (!IsInTerminalState) { // If we are STATE_NOT_INITIALIZED, the we probably threw from the ctor. // The finalizer will be called anyway and we need to free this partially constructed object correctly. // So we avoid throwing when we are in STATE_NOT_INITIALIZED. // In other words throw only if *some* async state is set: if (0 != (_state & STATEMASK_SELECT_ANY_ASYNC_STATE)) { InvalidOperationException ex = new InvalidOperationException(SR.InvalidOperation_IllegalStateChange); ex.SetHResult(E_ILLEGAL_STATE_CHANGE); throw ex; } } TransitionToClosed(); }