Last active
May 31, 2019 18:15
-
-
Save aliabidzaidi/22cd80ffe762250521e5ccbcd730f3cd to your computer and use it in GitHub Desktop.
Different ways to create tasks in .net
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
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