Windows Dev Center

IAsyncActionWithProgress<TProgress> interface

Represents an asynchronous action that can report progress updates to callers. This is the return type for all Windows Runtime asynchronous methods that don't have a result object, but do report progress to callback listeners.

Syntax


public interface IAsyncActionWithProgress<TProgress> : IAsyncInfo

Type parameters

TProgress

The type of the progress data.

Members

The IAsyncActionWithProgress interface has these types of members:

Methods

The IAsyncActionWithProgress interface has these methods. It also inherits methods from the Object class.

MethodDescription
GetResults Returns the results of the action.

 

Properties

The IAsyncActionWithProgress interface has these properties.

PropertyAccess typeDescription

Completed

Read/writeGets or sets the method that handles the action completed notification.

Progress

Read/writeGets or sets the callback method that receives progress notification.

 

Remarks

IAsyncActionWithProgress<TProgress> is the return type for all Windows Runtime asynchronous methods that don't communicate a result object, but do enable an app to check the progress of the action. There aren't nearly as many of these as there are methods that use IAsyncAction. IAsyncAction APIs don't report progress and don't have a result.

When you use methods that return IAsyncActionWithProgress<TProgress> in your app code, you usually don't access the IAsyncAction return value directly. That's because you almost always use the language-specific awaitable syntax. In this case, the apparent return value of the method is void. For more info, see Asynchronous programming, or one of the language-specific guides to Windows Runtime asynchronous programming (C#/Visual Basic, C++, JavaScript).

It's not common to use IAsyncActionWithProgress<TProgress> directly even if you don't use a language-specific awaitable syntax. Each of the languages has extension points that are generally easier to use than the Windows Runtime interface. JavaScript has WinJS.Promise, and the then/done with onProgress syntax. .NET has the AsTask extension methods, and once the IAsyncActionWithProgress<TProgress> is converted to a Task, it's easier to cancel, get notification on completion, use IProgress<T>, and so on. For C++/CX, you can wrap the calls using the Concurrency runtime (and use create_task). In other words, IAsyncActionWithProgress<TProgress> can be considered runtime-level infrastructure, which each of the languages use as a framework to support awaitable syntax or asynchronous programming models in their own way.

Specifically, if you want to handle progress in .NET code, use the AsTask signature that in an extension usage has a single IProgress reference parameter. (In this usage, the progress unit is already constrained and matches the IAsyncActionWithProgress method you're using.) Provide an object that implements IProgress, and your Report method implementation is invoked each time the Windows Runtime method reports a progress notification.

To monitor the progress of the action (if not using the language-specific techniques described above), set the Progress property, providing it the name of a method that implements the AsyncActionProgressHandler<TProgress> delegate.

Interface inheritance

IAsyncActionWithProgress<TProgress> inherits IAsyncInfo.Types that implement IAsyncActionWithProgress<TProgress> also implement the interface members of IAsyncInfo:

Notes to implementers

As with calling the existing methods, there are language-specific ways to define asynchronous methods that don't use IAsyncActionWithProgress<TProgress> directly. If writing code using .NET, your method can return a Task. For C++/CX, you can use the Concurrency runtime. However, if you're defining a Windows Runtime component, you can use Task/task internally but you must return one of the Windows Runtime interfaces for your public methods. The language-specific asynchronous support types (and many other language-specific types you might conventionally use in code) can't be used for the public surface area of a Windows Runtime component.

Requirements (Windows 10 device family)

Device family

Universal

API contract

Windows.Foundation.FoundationContract, introduced version 1.0

Namespace

Windows.Foundation
Windows::Foundation [C++]

Metadata

Windows.Foundation.FoundationContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

Windows.Foundation
Windows::Foundation [C++]

Metadata

Windows.winmd

Attributes

[Version(0x06020000)]

See also

IAsyncInfo
IAsyncAction

 

 

Show:
© 2015 Microsoft