Creating Tasks That Return Values

The Task class also has a generic counterpart that you can use for creating tasks that return a value. For example consider the following code snippet that creates a task returning a value of type Double, which is the result of calculating the tangent of an angle:

image

Console.WriteLine(taskWithResult.Result)

Basically you use a Function, which represents a System.Func(Of T) so that you can return a value from your operation. The result is accessed via the Task.Result property. In the preceding example, the Result property contains the result of the tangent calculation. The problem is that the start value on which ...

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.