-
Notifications
You must be signed in to change notification settings - Fork 22
UWP Dispatcher用法
L edited this page Feb 17, 2022
·
4 revisions
Task.Run(async () =>
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
ContentDialog dialog = new ContentDialog()
{
Title = "Test Dispatcher(测试Dispatcher)",
DefaultButton = ContentDialogButton.Close,
CloseButtonText = "Close(关闭)"
};
await dialog.ShowAsync();
});
});
根据CoreDispatcherPriority Enum,优先级分为:
High
:高优先级。 所有同步请求都会立即调用委托。 异步请求在任何其他请求类型之前排队和处理。
不要在应用程序中使用此优先级。 它是为系统事件保留的。 使用此优先级可能会导致其他消息(包括系统事件)被延迟。
Normal
:正常优先。 事件按安排的顺序进行处理。
Low
:低优先级。 如果队列中没有更高优先级的事件,则处理该事件。
Idle
:最低优先级。 将此优先级用于后台任务。 当窗口的主线程空闲并且队列中没有待处理的输入时,会处理委托。
CoreDispatcher Class
CoreDispatcher.RunAsync
CoreDispatcherPriority Enum
Getting the Dispatcher of a Window in UWP