Repository navigation
Question regarding ConfigureAwait(false)
#38
|
Hi, I have been trying to figure out a question of mine regarding: Basically, my question is: Is it OK to use ? The reason I'm asking is that And I wonder whether one can set view model properties (used in data bindings) on non-UI threads. Is it or is it not? Best regards! |
Replies: 1 comment 3 replies
|
Good question! Short answer: Yes, in .NET MAUI it's safe to update properties in the ViewModel that are bound to the view from any thread. .NET MAUI (and Xamarin.Forms) marshall binding updates to the Main (UI) Thread, so we're totally safe setting a property in our ViewModel from any thread because MAUI's binding engine will bring the updates to the UI Thread for us. You'll want to stay aware around this, though. There has been talks amongst the engineering team to no longer marshall every binding to the UI Thread, and I've seen some instances in newer versions of .NET MAUI where it wasn't properly marshaling CollectionView updates to the UI Thread. It'd be a substantial breaking change, and I don't they'd break all of our code, but it could happen! |
Good question!
Short answer: Yes, in .NET MAUI it's safe to update properties in the ViewModel that are bound to the view from any thread.
.NET MAUI (and Xamarin.Forms) marshall binding updates to the Main (UI) Thread, so we're totally safe setting a property in our ViewModel from any thread because MAUI's binding engine will bring the updates to the UI Thread for us.
You'll want to stay aware around this, though. There has been talks amongst the engineering team to no longer marshall every binding to the UI Thread, and I've seen some instances in newer versions of .NET MAUI where it wasn't properly marshaling CollectionView updates to the UI Thread. It'd be a substantial breaking change,…