Export (0) Print
Expand All

WindowsRuntimeSystemExtensions.AsTask(Of TResult, TProgress) Method (IAsyncOperationWithProgress(Of TResult, TProgress), CancellationToken)

.NET Framework 4.5

Returns a task that represents a Windows Runtime asynchronous operation that returns a result and can be cancelled.

Namespace:  System
Assembly:  System.Runtime.WindowsRuntime (in System.Runtime.WindowsRuntime.dll)

'Declaration
<ExtensionAttribute> _
Public Shared Function AsTask(Of TResult, TProgress) ( _
	source As IAsyncOperationWithProgress(Of TResult, TProgress), _
	cancellationToken As CancellationToken _
) As Task(Of TResult)

Type Parameters

TResult

The type of object that returns the result of the asynchronous operation.

TProgress

The type of object that provides data that indicates progress.

Parameters

source
Type: IAsyncOperationWithProgress(Of TResult, TProgress)

The asynchronous operation.

cancellationToken
Type: System.Threading.CancellationToken

A token that can be used to request cancellation of the asynchronous operation.

Return Value

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

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IAsyncOperationWithProgress(Of TResult, TProgress). 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

source is Nothing.

Use this method to get a Task(Of TResult) object for a Windows Runtime asynchronous operation. Task(Of TResult) objects simplify the coordination of asynchronous operations.

Calling this method overload is equivalent to calling the AsTask(Of TResult, TProgress)(IAsyncOperationWithProgress(Of TResult, TProgress), CancellationToken, IProgress(Of TProgress)) extension method overload and specifying Nothing for the progress parameter. This is useful when you don't want to get progress reports from an operation that reports progress.

.NET Framework

Supported in: 4.5

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone Silverlight 8

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012

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