TaskExtensions::Unwrap Method (Task<Task^>^)

 

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

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

public:
[ExtensionAttribute]
static Task^ Unwrap(
	Task<Task^>^ task
)

Parameters

task
Type: System.Threading.Tasks::Task<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).

Exception Condition
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<TResult>, where the inner Task represents work done as part of the outer Task<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:

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 5.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show: