Creating, Running, and Managing Tasks: The Task Class

The System.Threading.Tasks.Task class represents the unit of work in the parallel computing based on the .NET Framework. Differently from calling Parallel.Invoke, when you create an instance of the Task class, you get deep control over the task itself, such as starting, stopping, waiting for completion, and cancelation. The constructor of the class requires you to supply a delegate or a lambda expression to provide a method containing the code to be executed within the task. The following code demonstrates how you create a new task and then start it:

image

You supply the constructor with a lambda ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.