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.

public ref class CoreDispatcher sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class CoreDispatcher final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class CoreDispatcher
Public NotInheritable Class CoreDispatcher
Inheritance
Object Platform::Object IInspectable 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.

// 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());
}
void MyCoreWindowEvents::Run() // this is an implementation of IFrameworkView::Run() used to show context. It is called by CoreApplication::Run().
{
    CoreWindow::GetForCurrentThread()->Activate();

    //...

    CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
}

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