Unwrap Method (Task(Task))

Task Parallel System.Threading

Creates a proxy Task that represents the asynchronous operation of a Task{Task}.

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

Syntax

Visual Basic (Declaration)
Public Shared Function Unwrap ( _
	task As Task(Of Task) _
) As Task
C#
public static Task Unwrap(
	Task<Task> task
)

Parameters

task
Type: System.Threading.Tasks..::.Task<(Of <(Task>)>)
The Task{Task} to unwrap.

Return Value

A Task that represents the asynchronous operation of the provided Task{Task}.

Remarks

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}, 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{Task}.

Exceptions

ExceptionCondition
System..::.ArgumentNullExceptionThe exception that is thrown if the task argument is null.

See Also