当前位置:网站首页>Uwp dispatcher usage

Uwp dispatcher usage

2022-06-21 22:34:00 zLulus

Task.Run(async () =>
{
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
        {
            ContentDialog dialog = new ContentDialog()
            {
                Title = "Test Dispatcher( test Dispatcher)",
                DefaultButton = ContentDialogButton.Close,
                CloseButtonText = "Close( close )"
            };
            await dialog.ShowAsync();
        });
});

according to CoreDispatcherPriority Enum, Priority is divided into :
High: High priority . All synchronous requests immediately invoke the delegate . Asynchronous requests are queued and processed before any other request type .
Do not use this priority in your application . It is reserved for system events . Using this priority may result in other messages ( Including system events ) Delayed .
Normal: Normal first . Events are handled in a scheduled order .
Low: Low priority . If there is no higher priority event in the queue , The event is handled .
Idle: Lowest priority . Use this priority for background tasks . When the main thread of the window is idle and there is no pending input in the queue , Can handle delegation .

Sample code

DispatcherDemo.xaml.cs

Reference material

CoreDispatcher Class
CoreDispatcher.RunAsync
CoreDispatcherPriority Enum
Getting the Dispatcher of a Window in UWP

原网站

版权声明
本文为[zLulus]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206212041017542.html