Skip to content

Instantly share code, notes, and snippets.

@aliabidzaidi
Created May 31, 2019 18:05
Show Gist options
  • Save aliabidzaidi/6ff904fad0cf91de382106acde91d536 to your computer and use it in GitHub Desktop.
Save aliabidzaidi/6ff904fad0cf91de382106acde91d536 to your computer and use it in GitHub Desktop.
Different ways to create a task and setting their task states
Task t1 = new Task(new Action<object>(printMessage), "Task 1"); //Use Action Delegate with Named Method + Setting State
t1.Start();
Task t2 = new Task(delegate (Object obj) { Console.WriteLine("Hello Alien! I am from {0}", obj); }, "Task 2"); //Use an anonymous delegate + Setting State
t2.Start();
Task t3 = new Task((obj) => printMessage(obj), "Task 3"); //Use Lambda Expression and named method + Setting State
t3.Start();
Task t4 = new Task((obj) => { Console.WriteLine("Hello Alien! I am from {0}", obj); }, "Task 4"); //Use Lambda Expression and an anonymous method + Setting Task State
t4.Start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment