Skip to content

Instantly share code, notes, and snippets.

@aliabidzaidi
Last active June 1, 2019 07:09
Show Gist options
  • Save aliabidzaidi/1c01b806a64efe6eb365f705bac091e3 to your computer and use it in GitHub Desktop.
Save aliabidzaidi/1c01b806a64efe6eb365f705bac091e3 to your computer and use it in GitHub Desktop.
Creating task, returning result and passing state with TaskFactory
//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