Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. public static void HelloTask()
  2. {
  3. Thread.Sleep(1000);
  4. Console.WriteLine("Hello");
  5. }
  6.  
  7. public static void WorldTask()
  8. {
  9. Thread.Sleep(1000);
  10. Console.WriteLine("World");
  11. }
  12. public static void ContinuationTask()
  13. {
  14. Task task = Task.Run(() => HelloTask());
  15. //Starts executing this after completion of HelloTask.
  16. //if the antecedent task produces result, it can be supplied as input to continuation taks
  17. task.ContinueWith((prevTask) => WorldTask());
  18. //Overloads
  19. task.ContinueWith((prevTask) => WorldTask(), TaskContinuationOptions.OnlyOnRanToCompletion);
  20. task.ContinueWith((prevTask) => WorldTask(), TaskContinuationOptions.OnlyOnFaulted);
  21.  
  22. Console.WriteLine("Finished Processing. Press a key to end");
  23. Console.ReadKey();
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement