Running Tasks with Parallel.Invoke

The first way of running tasks in parallel is calling the Parallel.Invoke shared method. This method can receive an array of System.Action objects as parameters, so each Action is translated by the runtime into a task. If possible, tasks are executed in parallel. The following example demonstrates how to perform three calculations concurrently:

'Requires an Imports System.Threading.Tasks directive    Dim angle As Double = 150    Dim sineResult As Double    Dim cosineResult As Double    Dim tangentResult As Double    Parallel.Invoke(Sub()                        Console.WriteLine(Thread.CurrentThread.                                          ManagedThreadId)                        Dim ...

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.