Different ways to start a Task in C#

CsharpProgrammingServer Side Programming

To start a task in C#, follow any of the below given ways.

Use a delegate to start a task.

Task t = new Task(delegate { PrintMessage(); });
t.Start();

Use Task Factory to start a task.

Task.Factory.StartNew(() => {Console.WriteLine("Welcome!"); });

You can also use Lambda.

Task t = new Task( () => PrintMessage() );
t.Start();
raja
Published on 17-Sep-2018 16:52:26
Advertisements