Unwrap Method (Task(Task))
Collapse the table of content
Expand the table of content

TaskExtensions.Unwrap Method (Task(Of Task))

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Creates a proxy Task that represents the asynchronous operation of a TryExecuteTaskInline.

Namespace:  System.Threading.Tasks
Assembly:  System.Core (in System.Core.dll)

'Declaration
<ExtensionAttribute> _
Public Shared Function Unwrap ( _
	task As Task(Of Task) _
) As Task

Parameters

task
Type: System.Threading.Tasks.Task(Of Task)
The Task<Task> (C#) or Task (Of Task) (Visual Basic) to unwrap.

Return Value

Type: System.Threading.Tasks.Task
A Task that represents the asynchronous operation of the provided System.Threading.Tasks.Task(Of Task).

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Task(Of Task). When you use instance method syntax to call this method, omit the first parameter.

ExceptionCondition
ArgumentNullException

The exception that is thrown if the task argument is null.

It is often useful to be able to return a Task from a Task(Of TResult), where the inner Task represents work done as part of the outer Task(Of TResult). However, doing so results in a Task<Task> (C#) or Task (Of Task) (Visual Basic), which, if not dealt with carefully, could produce unexpected behavior. Unwrap solves this problem by creating a proxy Task that represents the entire asynchronous operation of such a task.

The following example shows how to unwrap a task:

Windows Phone OS

Supported in: 8.1, 8.0

Show:
© 2017 Microsoft