CoreDispatcher 類別

定義

提供Windows 執行階段核心事件訊息發送器。 此類型的實例負責處理視窗訊息,並將事件分派給用戶端。

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
繼承
Object Platform::Object IInspectable CoreDispatcher
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

備註

您可以從 CoreWindow.Dispatcher 屬性取得此類型的實例。 呼叫CoreWindow.GetForCurrentThread即可取得目前的CoreWindow實例。

// 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);
}

屬性

CurrentPriority

取得並設定目前工作的優先順序。

HasThreadAccess

取得值,這個值會指定 CoreWindow 實例所提供的事件發送器是否具有目前線程的存取權。

方法

ProcessEvents(CoreProcessEventsOption)

啟動發送器,此 CoreWindow實例的輸入事件佇列。

RunAsync(CoreDispatcherPriority, DispatchedHandler)

從背景工作執行緒排程 UI 執行緒上提供的回呼,並以非同步方式傳回結果。

RunIdleAsync(IdleDispatchedHandler)

從處於閒置優先順序的背景工作執行緒排程 UI 執行緒上的回呼,並以非同步方式傳回結果。

ShouldYield()

查詢呼叫端是否應該在工作佇列中有優先順序高於目前工作的專案時產生。

ShouldYield(CoreDispatcherPriority)

查詢呼叫端是否應該在指定優先順序或更高的工作佇列中有專案時產生。

StopProcessEvents()

停止發送器處理任何佇列事件。

TryRunAsync(CoreDispatcherPriority, DispatchedHandler)

嘗試從背景工作執行緒在 UI 執行緒上排程指定的回呼,並以非同步方式傳回結果。

TryRunIdleAsync(IdleDispatchedHandler)

嘗試從處於閒置優先順序的背景工作執行緒排程 UI 執行緒上的回呼,並以非同步方式傳回結果。

事件

AcceleratorKeyActivated

啟動快速鍵時引發, (按下或按住) 。

適用於