Guest User

Untitled

a guest
Oct 18th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. public static class TaskExtensions
  2. {
  3. private static Action<Task> IgnorerContinuationAction = IgnorerContinuation;
  4.  
  5. public static void Ignore(this Task task)
  6. {
  7. if (task.IsCompleted)
  8. {
  9. var exception = task.Exception;
  10. }
  11. else
  12. {
  13. task.ContinueWith(
  14. IgnorerContinuationAction,
  15. CancellationToken.None,
  16. TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously,
  17. TaskScheduler.Default);
  18. }
  19. }
  20.  
  21. private static void IgnorerContinuation(Task task)
  22. {
  23. var exception = task.Exception;
  24. }
  25. }
Add Comment
Please, Sign In to add comment