Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
72
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 int CalculateResult()
  2. {
  3. Console.WriteLine("Work Starting");
  4. Thread.Sleep(2000);
  5. Console.WriteLine("Work Finished");
  6. return 99;
  7. }
  8. public static void ReturnValue()
  9. {
  10. //creating task with return value
  11. Task<int> task = Task.Run(() =>
  12. {
  13. return CalculateResult();
  14. });
  15. //program waits when result property is read
  16. Console.WriteLine(task.Result);
  17. Console.WriteLine("Finished Processing. Press a key to end");
  18. Console.ReadKey();
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement