CoreDispatcher CoreDispatcher CoreDispatcher 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 : sealed class CoreDispatcher : ICoreAcceleratorKeys, ICoreDispatcher, ICoreDispatcher2, ICoreDispatcherWithTaskPriority
struct winrt::Windows::UI::Core::CoreDispatcher : ICoreAcceleratorKeys, ICoreDispatcher, ICoreDispatcher2, ICoreDispatcherWithTaskPriority
public sealed class CoreDispatcher : ICoreAcceleratorKeys, ICoreDispatcher, ICoreDispatcher2, ICoreDispatcherWithTaskPriority
Public NotInheritable Class CoreDispatcher Implements ICoreAcceleratorKeys, ICoreDispatcher, ICoreDispatcher2, ICoreDispatcherWithTaskPriority
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 CurrentPriority CurrentPriority CurrentPriority

Gets and sets the priority of the current task.

HasThreadAccess HasThreadAccess HasThreadAccess 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) ProcessEvents(CoreProcessEventsOption) ProcessEvents(CoreProcessEventsOption) ProcessEvents(CoreProcessEventsOption)

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

RunAsync(CoreDispatcherPriority, DispatchedHandler) RunAsync(CoreDispatcherPriority, DispatchedHandler) RunAsync(CoreDispatcherPriority, DispatchedHandler) RunAsync(CoreDispatcherPriority, DispatchedHandler)

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

RunIdleAsync(IdleDispatchedHandler) RunIdleAsync(IdleDispatchedHandler) RunIdleAsync(IdleDispatchedHandler) RunIdleAsync(IdleDispatchedHandler)

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

ShouldYield() ShouldYield() ShouldYield() ShouldYield()

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

ShouldYield(CoreDispatcherPriority) ShouldYield(CoreDispatcherPriority) ShouldYield(CoreDispatcherPriority) ShouldYield(CoreDispatcherPriority)

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

StopProcessEvents() StopProcessEvents() StopProcessEvents() StopProcessEvents()

Stops the dispatcher from processing any queued events.

TryRunAsync(CoreDispatcherPriority, DispatchedHandler) TryRunAsync(CoreDispatcherPriority, DispatchedHandler) TryRunAsync(CoreDispatcherPriority, DispatchedHandler) TryRunAsync(CoreDispatcherPriority, DispatchedHandler)

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

TryRunIdleAsync(IdleDispatchedHandler) TryRunIdleAsync(IdleDispatchedHandler) TryRunIdleAsync(IdleDispatchedHandler) 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 AcceleratorKeyActivated AcceleratorKeyActivated AcceleratorKeyActivated

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