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(); });
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();
Updated on: 2019-07-30T22:30:23+05:30

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements