Export (0) Print
Expand All

TaskExtensions.Unwrap<TResult> Method (Task<Task<TResult>>)

Creates a proxy Task that represents the asynchronous operation of a Task<Task<T>> (C#) or Task (Of Task(Of T)) (Visual Basic).

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

public static Task<TResult> Unwrap<TResult>(
	this Task<Task<TResult>> task
)

Type Parameters

TResult

The type of the task's result.

Parameters

task
Type: System.Threading.Tasks.Task<Task<TResult>>

The Task<Task<T>> (C#) or Task (Of Task(Of T)) (Visual Basic) to unwrap.

Return Value

Type: System.Threading.Tasks.Task<TResult>
A Task that represents the asynchronous operation of the provided Task<Task<T>> (C#) or Task (Of Task(Of T)) (Visual Basic).

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Task<Task<TResult>>. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

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, where the inner Task represents work done as part of the outer Task. However, doing so results in a Task<Task<T>> (C#) or Task (Of Task(Of T)) (Visual Basic), which, if not dealt with carefully, could produce unexpected behavior. Unwrap solves this problem by creating a proxy Task<TResult> that represents the entire asynchronous operation of such a Task<Task<T>> (C#) or Task (Of Task(Of T)) (Visual Basic).

.NET Framework

Supported in: 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft