I have a library in .Net Standard 2.0 that is used in multiple projets (Xamarin, WPF, ...), which uses ObservableCollection in order to bind them in WPF or to be able to react to their modifications.
When I try to remove an element from theses collections from a new thread. It then throw a "NotSupportedException", which is usually resolved by using the Dispatcher, to call the remove method from the UI thread.
The problem is that .Net Standard does not provide the Dispatcher (which makes sense, since there might be no UI thread). So this leads to my question; how do I go about modifying theses collections from another thread without a Dispatcher? Am I doing something that I shouldn't do by using ObservableCollections here?
The exception:
System.NotSupportedException: This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread.
à System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
à System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
à ALX.GroundStation.Host.Infrastructure.ReadOnlyObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)