public bool TrySetCanceled(OperationCanceledException exception) { if (Interlocked.CompareExchange(ref state, Canceled, Pending) == Pending) { this.exception = new ExceptionHolder(ExceptionDispatchInfo.Capture(exception)); TryInvokeContinuation(); return true; } return false; }
public bool TrySetException(Exception exception) { if (Interlocked.CompareExchange(ref state, Faulted, Pending) == Pending) { this.exception = new ExceptionHolder(ExceptionDispatchInfo.Capture(exception)); TryInvokeContinuation(); return(true); } return(false); }