TaskExtensions.Unwrap<TResult> Method (Task<Task<TResult>>)
Microsoft Silverlight will reach end of support after October 2021. Learn more.
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)
Syntax
'Declaration
<ExtensionAttribute> _
Public Shared Function Unwrap(Of TResult) ( _
task As Task(Of Task(Of TResult)) _
) As Task(Of TResult)
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 [System.Threading.Tasks.Task`1] 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.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | The exception that is thrown if the task argument is null. |
Remarks
It is often useful to be able to return a [System.Threading.Tasks.Task`1] from a [System.Threading.Tasks.Task`1], where the inner [System.Threading.Tasks.Task`1] represents work done as part of the outer [System.Threading.Tasks.Task`1]. 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 [System.Threading.Tasks.Task`1] that represents the entire asynchronous operation of such a Task<Task<T>> (C#) or Task (Of Task(Of T)) (Visual Basic).
Version Information
Silverlight
Supported in: 5
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
See Also