WindowsRuntimeSystemExtensions.AsTask Method

Definition

Overloads

AsTask(IAsyncAction)

Returns a task that represents a Windows Runtime asynchronous action.

AsTask(IAsyncAction, CancellationToken)

Returns a task that represents a Windows Runtime asynchronous action that can be cancelled.

AsTask<TProgress>(IAsyncActionWithProgress<TProgress>)

Returns a task that represents a Windows Runtime asynchronous action.

AsTask<TProgress>(IAsyncActionWithProgress<TProgress>, IProgress<TProgress>)

Returns a task that represents a Windows Runtime asynchronous action that reports progress.

AsTask<TProgress>(IAsyncActionWithProgress<TProgress>, CancellationToken)

Returns a task that represents a Windows Runtime asynchronous action that can be cancelled.

AsTask<TProgress>(IAsyncActionWithProgress<TProgress>, CancellationToken, IProgress<TProgress>)

Returns a task that represents a Windows Runtime asynchronous action that reports progress and can be cancelled.

AsTask<TResult,TProgress>(IAsyncOperationWithProgress<TResult,TProgress>, CancellationToken, IProgress<TProgress>)

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

AsTask<TResult,TProgress>(IAsyncOperationWithProgress<TResult,TProgress>, CancellationToken)

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

AsTask<TResult,TProgress>(IAsyncOperationWithProgress<TResult,TProgress>)

Returns a task that represents a Windows Runtime asynchronous operation returns a result.

AsTask<TResult,TProgress>(IAsyncOperationWithProgress<TResult,TProgress>, IProgress<TProgress>)

Returns a task that represents Windows Runtime asynchronous operation that returns a result and reports progress.

AsTask<TResult>(IAsyncOperation<TResult>)

Returns a task that represents a Windows Runtime asynchronous operation returns a result.

AsTask<TResult>(IAsyncOperation<TResult>, CancellationToken)

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

AsTask(IAsyncAction)

Returns a task that represents a Windows Runtime asynchronous action.

C#
public static System.Threading.Tasks.Task AsTask(this Windows.Foundation.IAsyncAction source);

Parameters

source
IAsyncAction

The asynchronous action.

Returns

A task that represents the asynchronous action.

Exceptions

source is null.

Remarks

Note

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0

AsTask(IAsyncAction, CancellationToken)

Returns a task that represents a Windows Runtime asynchronous action that can be cancelled.

C#
public static System.Threading.Tasks.Task AsTask(this Windows.Foundation.IAsyncAction source, System.Threading.CancellationToken cancellationToken);

Parameters

source
IAsyncAction

The asynchronous action.

cancellationToken
CancellationToken

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

Returns

A task that represents the asynchronous action.

Exceptions

source is null.

Remarks

Note

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0

AsTask<TProgress>(IAsyncActionWithProgress<TProgress>)

Returns a task that represents a Windows Runtime asynchronous action.

C#
public static System.Threading.Tasks.Task AsTask<TProgress>(this Windows.Foundation.IAsyncActionWithProgress<TProgress> source);

Type Parameters

TProgress

The type of object that provides data that indicates progress.

Parameters

source
IAsyncActionWithProgress<TProgress>

The asynchronous action.

Returns

A task that represents the asynchronous action.

Exceptions

source is null.

Remarks

Note

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

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0

AsTask<TProgress>(IAsyncActionWithProgress<TProgress>, IProgress<TProgress>)

Returns a task that represents a Windows Runtime asynchronous action that reports progress.

C#
public static System.Threading.Tasks.Task AsTask<TProgress>(this Windows.Foundation.IAsyncActionWithProgress<TProgress> source, IProgress<TProgress> progress);

Type Parameters

TProgress

The type of object that provides data that indicates progress.

Parameters

source
IAsyncActionWithProgress<TProgress>

The asynchronous action.

progress
IProgress<TProgress>

An object that receives progress updates.

Returns

A task that represents the asynchronous action.

Exceptions

source is null.

Remarks

Note

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0

AsTask<TProgress>(IAsyncActionWithProgress<TProgress>, CancellationToken)

Returns a task that represents a Windows Runtime asynchronous action that can be cancelled.

C#
public static System.Threading.Tasks.Task AsTask<TProgress>(this Windows.Foundation.IAsyncActionWithProgress<TProgress> source, System.Threading.CancellationToken cancellationToken);

Type Parameters

TProgress

The type of object that provides data that indicates progress.

Parameters

source
IAsyncActionWithProgress<TProgress>

The asynchronous action.

cancellationToken
CancellationToken

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

Returns

A task that represents the asynchronous action.

Exceptions

source is null.

Remarks

Note

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

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0

AsTask<TProgress>(IAsyncActionWithProgress<TProgress>, CancellationToken, IProgress<TProgress>)

Returns a task that represents a Windows Runtime asynchronous action that reports progress and can be cancelled.

C#
public static System.Threading.Tasks.Task AsTask<TProgress>(this Windows.Foundation.IAsyncActionWithProgress<TProgress> source, System.Threading.CancellationToken cancellationToken, IProgress<TProgress> progress);

Type Parameters

TProgress

The type of object that provides data that indicates progress.

Parameters

source
IAsyncActionWithProgress<TProgress>

The asynchronous action.

cancellationToken
CancellationToken

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

progress
IProgress<TProgress>

An object that receives progress updates.

Returns

A task that represents the asynchronous action.

Exceptions

source is null.

Remarks

Note

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0

AsTask<TResult,TProgress>(IAsyncOperationWithProgress<TResult,TProgress>, CancellationToken, IProgress<TProgress>)

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

C#
public static System.Threading.Tasks.Task<TResult> AsTask<TResult,TProgress>(this Windows.Foundation.IAsyncOperationWithProgress<TResult,TProgress> source, System.Threading.CancellationToken cancellationToken, IProgress<TProgress> progress);

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
IAsyncOperationWithProgress<TResult,TProgress>

The asynchronous operation.

cancellationToken
CancellationToken

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

progress
IProgress<TProgress>

An object that receives progress updates.

Returns

A task that represents the asynchronous operation.

Remarks

Note

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0

AsTask<TResult,TProgress>(IAsyncOperationWithProgress<TResult,TProgress>, CancellationToken)

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

C#
public static System.Threading.Tasks.Task<TResult> AsTask<TResult,TProgress>(this Windows.Foundation.IAsyncOperationWithProgress<TResult,TProgress> source, System.Threading.CancellationToken cancellationToken);

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
IAsyncOperationWithProgress<TResult,TProgress>

The asynchronous operation.

cancellationToken
CancellationToken

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

Returns

A task that represents the asynchronous operation.

Exceptions

source is null.

Remarks

Note

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

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0

AsTask<TResult,TProgress>(IAsyncOperationWithProgress<TResult,TProgress>)

Returns a task that represents a Windows Runtime asynchronous operation returns a result.

C#
public static System.Threading.Tasks.Task<TResult> AsTask<TResult,TProgress>(this Windows.Foundation.IAsyncOperationWithProgress<TResult,TProgress> source);

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
IAsyncOperationWithProgress<TResult,TProgress>

The asynchronous operation.

Returns

A task that represents the asynchronous operation.

Exceptions

source is null.

Remarks

Note

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

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0

AsTask<TResult,TProgress>(IAsyncOperationWithProgress<TResult,TProgress>, IProgress<TProgress>)

Returns a task that represents Windows Runtime asynchronous operation that returns a result and reports progress.

C#
public static System.Threading.Tasks.Task<TResult> AsTask<TResult,TProgress>(this Windows.Foundation.IAsyncOperationWithProgress<TResult,TProgress> source, IProgress<TProgress> progress);

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
IAsyncOperationWithProgress<TResult,TProgress>

The asynchronous operation.

progress
IProgress<TProgress>

An object that receives progress updates.

Returns

A task that represents the asynchronous operation.

Exceptions

source is null.

Remarks

Note

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0

AsTask<TResult>(IAsyncOperation<TResult>)

Returns a task that represents a Windows Runtime asynchronous operation returns a result.

C#
public static System.Threading.Tasks.Task<TResult> AsTask<TResult>(this Windows.Foundation.IAsyncOperation<TResult> source);

Type Parameters

TResult

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

Parameters

source
IAsyncOperation<TResult>

The asynchronous operation.

Returns

A task that represents the asynchronous operation.

Exceptions

source is null.

Remarks

Note

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0

AsTask<TResult>(IAsyncOperation<TResult>, CancellationToken)

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

C#
public static System.Threading.Tasks.Task<TResult> AsTask<TResult>(this Windows.Foundation.IAsyncOperation<TResult> source, System.Threading.CancellationToken cancellationToken);

Type Parameters

TResult

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

Parameters

source
IAsyncOperation<TResult>

The asynchronous operation.

cancellationToken
CancellationToken

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

Returns

A task that represents the asynchronous operation.

Exceptions

source is null.

Remarks

Note

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

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

Applies to

UWP 10.0
Product Versions
UWP 10.0