Last active
June 1, 2019 07:09
-
-
Save aliabidzaidi/1c01b806a64efe6eb365f705bac091e3 to your computer and use it in GitHub Desktop.
Creating task, returning result and passing state with TaskFactory
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
//Create a simple task using taskfactory | |
Task.Factory.StartNew(() => { Console.WriteLine("Simple Task of Factory"); }); | |
//Create a task using factory + Setting Task State + Returning Result | |
Task<int> T1 = Task.Factory.StartNew<int>(obj => | |
{ | |
int a = (int)obj; | |
return a * a; | |
}, 10); | |
Console.WriteLine("(Not)Simple Task of Factory" + T1.Result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment