Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int CalculateResult()
- {
- Console.WriteLine("Work Starting");
- Thread.Sleep(2000);
- Console.WriteLine("Work Finished");
- return 99;
- }
- public static void ReturnValue()
- {
- //creating task with return value
- Task<int> task = Task.Run(() =>
- {
- return CalculateResult();
- });
- //program waits when result property is read
- Console.WriteLine(task.Result);
- Console.WriteLine("Finished Processing. Press a key to end");
- Console.ReadKey();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement