Home > OS >  How do you update the UI thread using .Net 6?
How do you update the UI thread using .Net 6?

Time:12-17

In .NET 4.x I could run code in a non-UI thread and update a WPF (or UWP) control in the UI thread with something like this (Messages is a string property in the ViewModel referenced by the UI which triggers OnPropertyChanged()):

App.Current.Dispatcher.Invoke(new Action(() => Messages  = (message   Environment.NewLine)));

How can you access the UI thread with .NET 6?

I've looked all thru the System.Threading namespace and can't find any reference to a dispatcher similar that found in .NET 4.x. I can find a reference to the current thread thru System.Threading.Thread.CurrentThread, but I'm not sure how to dispatch an action into that thread.

CodePudding user response:

Since you know how to use the Dispatcher in WPF and UWP, I guess your question is about WinUI 3. For WinUI 3, use DispatcherQueue. Bisedes that, there is DispatcherHelper from Community Toolkit.

  • Related