Skip to content

Instantly share code, notes, and snippets.

@aliabidzaidi
Last active May 31, 2019 18:15
Show Gist options
  • Save aliabidzaidi/22cd80ffe762250521e5ccbcd730f3cd to your computer and use it in GitHub Desktop.
Save aliabidzaidi/22cd80ffe762250521e5ccbcd730f3cd to your computer and use it in GitHub Desktop.
Different ways to create tasks in .net
Task.Factory.StartNew(() => { Console.WriteLine("I am from another ThreadPlanet"); }); //Creating task using Factory
Task t1 = new Task(new Action(printMessage)); //Use Action Delegate With Named Method
t1.Start();
Task t2 = new Task(delegate { Console.WriteLine("Hello Alien!"); }); //Use an anonymous delegate
t2.Start();
Task t3 = new Task(() => printMessage()); //Use Lambda Expression and named method
t3.Start();
Task t4 = new Task(() => { Console.WriteLine("Hello Alien!"); }); //Use Lambda Expression and an anonymous method
t4.Start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment