AsyncInfo.Run<TResult, TProgress> Method (Func<CancellationToken, IProgress<TProgress>, Task<TResult>>)

.NET Framework 4.5

Creates and starts a Windows Runtime asynchronous operation that includes progress updates, by using a function that generates a started task that returns results. The task can support cancellation and progress reporting.

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

public static IAsyncOperationWithProgress<TResult, TProgress> Run<TResult, TProgress>(
	Func<CancellationToken, IProgress<TProgress>, Task<TResult>> taskProvider
)

Type Parameters

TResult

The type that returns the result.

TProgress

The type that is used for progress notifications.

Parameters

taskProvider
Type: System.Func<CancellationToken, IProgress<TProgress>, Task<TResult>>

A delegate that represents the function that creates and starts the task. The started task is represented by the Windows Runtime asynchronous action that is returned. The function is passed a cancellation token that the task can monitor to be notified of cancellation requests, and an interface for reporting progress; you can ignore either or both of these arguments if your task does not support progress reporting or cancellation.

Return Value

Type: IAsyncOperationWithProgress<TResult, TProgress>
A started Windows.Foundation.IAsyncOperationWithProgress<TResult,TProgress> instance that represents the task that is generated by taskProvider.

ExceptionCondition
ArgumentNullException

taskProvider is null.

InvalidOperationException

taskProvider returns an unstarted task.

This method passes a cancellation token to the function that is specified by taskProvider. This token provides a connection between Windows Runtime cancellation and .NET Framework task cancellation; if the action is canceled, the task is canceled. If your task does not support cancellation, ignore the token.

This method also passes an interface for reporting progress. The function that is specified by taskProvider can use this interface to report progress through the IAsyncOperationWithProgress<TProgress> instance. If your task does not support progress reporting, ignore the interface.

.NET Framework

Supported in: 4.5

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Silverlight 8.1

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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft