7 ways to start a Task in .NET C#

New threads can be started using the Task Programming Library in .NET in – at last – 5 different ways.

You’ll first need to add the following using statement:

The most direct way

Using Action

…where PrintMessage is a method:

Using a delegate

Lambda and named method

Lambda and anonymous method

Using Task.Run in .NET 4.5

Using Task.FromResult in .NET4.5 to return a result from a Task

You cannot start a task that has already completed. If you need to run the same task you’ll need to initialise it again.

Source:dotnetcodr.com

Please follow and like us:

Leave a reply

Your email address will not be published.