ObservableCollection in WPF The thread security modification
When using
in WPF, maintaining thread safety is very important. Try to modify from the work thread without appropriate synchronization. ObservableCollection
ObservableCollection
To modify
use the ObservableCollection
method on the UI thread . This method executes the following steps:
BindingOperations.EnableCollectionSynchronization
CollectionChanged
It obtains the lock on the set until the event of the group is processed. This can prevent the UI thread event processing program accessing it when the work thread is modified. Select the lock mechanism: OK that you will use the traditional sentence or custom synchronization mechanism.
lock
Get the lock before modifying: EnableCollectionSynchronization
The above is the detailed content of How to Ensure Thread-Safe Modifications of ObservableCollections in WPF?. For more information, please follow other related articles on the PHP Chinese website!