public void SetException_FaultsTask() { var e = new InvalidOperationException(); var tcs = new TaskCompletionSource(); tcs.SetException(e); Assert.IsTrue(tcs.Task.IsFaulted); Assert.AreSame(e, tcs.Task.Exception.InnerException); }
public void SetExceptions_FaultsTask() { var e = new[] { new InvalidOperationException() }; var tcs = new TaskCompletionSource(); tcs.SetException(e); Assert.IsTrue(tcs.Task.IsFaulted); Assert.IsTrue(tcs.Task.Exception.InnerExceptions.SequenceEqual(e)); }
/// <summary> /// Transitions the underlying <see cref="Task"/> into the <see cref="TaskStatus.Faulted"/> state. /// </summary> /// <param name="exception">The exception to bind to this <see cref="Task"/>. May not be <c>null</c>.</param> /// <exception cref="InvalidOperationException">The underlying <see cref="Task"/> has already been completed.</exception> public void SetException(Exception exception) { _tcs.SetException(exception); }
/// <summary> /// Invoked when the session is complete. Sets the results of the session on the given task source. /// </summary> /// <param name="tcs"></param> /// <param name="args"></param> void OnSessionCompleted(TaskCompletionSource<VoiceXmlResult> tcs, SessionCompletedEventArgs args) { if (tcs.Task.IsCompleted) return; Dispatch(() => { if (tcs.Task.IsCompleted) return; if (args.Cancelled) tcs.SetCanceled(); else if (args.Error != null) tcs.SetException(args.Error); else if (args.Result.UnhandledThrowElement != null) tcs.SetException(new UnhandledPageThrowException(args.Result.UnhandledThrowElement)); else tcs.SetResult(args.Result); }); }