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 .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 cancelling. 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:

Dim simpleTask As New Task(Sub()                               'Do your work here...                           End Sub) ...

Get Visual Basic 2015 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.