Replacing Dispatcher from UWP #7584
-
I'm looking at the Midi sample for UWP, it uses CoreDispatcher. How can I replace that with DispatcherQueue? It doesn't have a RunAsync method. So I don't understand how DispatcherQueue can replace it. Can I just get rid of the awaits in these usage of CoreDispatcher and make the methods synchronous? // UWP Code
private async void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
{
// If all devices have been enumerated
if (this.enumerationCompleted)
{
await coreDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
{
// Update the device list
UpdateDevices();
});
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The toolkit has an extension for that and here you can find a sample |
Beta Was this translation helpful? Give feedback.
-
You can see the Midi sample I had posted : WinUI3_Midi |
Beta Was this translation helpful? Give feedback.
The toolkit has an extension for that
https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/rel/7.1.2/Microsoft.Toolkit.Uwp/Extensions/DispatcherQueueExtensions.cs
and here you can find a sample
https://github.com/CommunityToolkit/WindowsCommunityToolkit/tree/rel/7.1.2/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DispatcherQueueHelper