public void SetCanceled_CancelsTask() { var tcs = new TaskCompletionSource(); tcs.SetCanceled(); Assert.IsTrue(tcs.Task.IsCanceled); }
/// <summary> /// Transitions the underlying <see cref="Task"/> into the <see cref="TaskStatus.Canceled"/> state. /// </summary> /// <exception cref="InvalidOperationException">The underlying <see cref="Task"/> has already been completed.</exception> public void SetCanceled() { _tcs.SetCanceled(); }
/// <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); }); }