Share via


CoreDispatcher.RunIdleAsync(IdleDispatchedHandler) Method

Definition

Schedules a callback on the UI thread from a worker thread at idle priority, and returns the results asynchronously.

public:
 virtual IAsyncAction ^ RunIdleAsync(IdleDispatchedHandler ^ agileCallback) = RunIdleAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncAction RunIdleAsync(IdleDispatchedHandler const& agileCallback);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncAction RunIdleAsync(IdleDispatchedHandler agileCallback);
function runIdleAsync(agileCallback)
Public Function RunIdleAsync (agileCallback As IdleDispatchedHandler) As IAsyncAction

Parameters

agileCallback
IdleDispatchedHandler

The callback on which the idle priority dispatcher returns when the event is dispatched.

Returns

Object that contains the results of the asynchronous action.

Attributes

Remarks

The RunIdleAsync method is very similar to CoreDispatcher.RunAsync, except that it always schedules the work item at CoreDispatcherPriority.Low priority. When you schedule a work item by calling RunIdleAsync from a worker thread, the work item is processed only when there are no event messages pending in the queue. This allows your app to perform tasks such as spell check or other discrete processing while the system is idle. If the IdleDispatchedHandler delegate returned by the callback has the IsDispatcherIdle property set to false, the work item immediately exits background processing until the event queue is empty again.

However, while your app is processing a background task, it can continue processing as long as there are no event messages pending in the CoreDispatcher event message queue. If your app receives an event message in the queue, then it must break out of the background processing. To determine when your app must exit background processing, access the IsDispatcherIdle property on the IdleDispatchedHandlerArgs object returned by the IdleDispatchedHandler callback you provided to RunIdleAsync. If there is a message, exit background processing and set the priority to CoreDispatcherPriority.Normal. Otherwise, if the callback continues to run without checking the dispatcher status, it could lead to input starvation.

Applies to

See also