Different ways to start a Task in C#

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(); });

Use Task Factory to start a task.

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

You can also use Lambda.

Task t = new Task( () => PrintMessage() );
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know