Replies: 2 comments
-
You can use Dispatcher.UIThread.Post to update the collection. The data can be fetched async. Alternative is to use the package 3rd party ObservableCollections or DynamicData which is shipped via ReactiveUI |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi @timunie, Dispatcher.UIThread.Post is easy, and I would have used it if I had received an exception from Avalonia that I should do it. However, I don't see it. I can modify the observable collection from any thread, and it usually works. This is my understanding why: when the binding happens, Avalonia needs to perform steps:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone, we are moving our application from WPF to Avalonia. In WPF, if you modify an
ObservableCollection
that has a binding by UI from not UI thread, you instantly get an exception. So you have 2 options:BindingOperations.EnableCollectionSynchronization
. This way, all modifications should be wrapped withlockObject
by the developer. On the other side, WPF uses the samelockObject
when it readsObservableCollection
.With Avalonia, we get no exceptions when we modify
ObservableCollection
outside of the UI thread. However, there's noBindingOperations.EnableCollectionSynchronization
analog, so I assume the operations are not thread-safe. We catch the following exception sometimes on collection modification, which proves my concerns on thread-safety issues. Exceptions examples:or
My question is: Is there truly no analog of
BindingOperations.EnableCollectionSynchronization
in Avalonia, and we need to modifyObservableCollection
on UI thread only? Or there's another way to achieve what we do in WPF (option 2)?Beta Was this translation helpful? Give feedback.
All reactions