Last active
June 2, 2019 17:15
-
-
Save aliabidzaidi/97f8860073b9b9673a3dea8aa181f49a to your computer and use it in GitHub Desktop.
Returning result from a task and passing state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int number = 10; | |
//Using task factory + Setting Task State + Returning Result | |
Task<int> T1 = Task.Factory.StartNew<int>(obj => | |
{ | |
int num = (int)obj; | |
return num * num; | |
}, number); | |
Console.WriteLine("T1 Task Result" + T1.Result); | |
//Return Result of a Task with anonymous method and passing state | |
Task<int> T2 = new Task<int>(obj => | |
{ | |
int num = (int)obj; | |
return num * num; | |
}, number); | |
T2.Start(); | |
Console.WriteLine("T2 Task Result=" + T2.Result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment