CoreDispatcher Class

Definition

Provides the Windows Runtime core event message dispatcher. Instances of this type are responsible for processing the window messages and dispatching the events to the client.

C#
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class CoreDispatcher
Inheritance
Object CoreDispatcher
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Remarks

Instances of this type can be obtained from the CoreWindow.Dispatcher property. The current CoreWindow instance can be obtained by calling CoreWindow.GetForCurrentThread.

C++/WinRT
// App.cpp
...
// An implementation of IFrameworkView::Run.
void Run()
{
    CoreWindow window{ CoreWindow::GetForCurrentThread() };
    window.Activate();

    CoreDispatcher dispatcher{ window.Dispatcher() };
    dispatcher.ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
}

// The CoreApplication::Run call indirectly calls the App::Run function above.
int __stdcall wWinMain(HINSTANCE, HINSTANCE, PWSTR, int)
{
    CoreApplication::Run(App());
}

Properties

CurrentPriority

Gets and sets the priority of the current task.

HasThreadAccess

Gets a value that specifies whether the event dispatcher provided by this instance of CoreWindow has access to the current thread or not.

Methods

ProcessEvents(CoreProcessEventsOption)

Starts the dispatcher processing the input event queue for this instance of CoreWindow.

RunAsync(CoreDispatcherPriority, DispatchedHandler)

Schedules the provided callback on the UI thread from a worker thread, and returns the results asynchronously.

RunIdleAsync(IdleDispatchedHandler)

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

ShouldYield()

Queries whether the caller should yield if there are items in the task queue of higher priority than the current task.

ShouldYield(CoreDispatcherPriority)

Queries whether the caller should yield if there are items in the task queue of the specified priority or higher.

StopProcessEvents()

Stops the dispatcher from processing any queued events.

TryRunAsync(CoreDispatcherPriority, DispatchedHandler)

Attempts to schedule the specified callback on the UI thread from a worker thread, and returns the results asynchronously.

TryRunIdleAsync(IdleDispatchedHandler)

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

Events

AcceleratorKeyActivated

Fired when an accelerator key is activated (pressed or held down).

Applies to

Product Versions
WinRT Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100