"This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread." code example
Example: "This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread."
using System.Collections.ObjectModel;
using System.Windows.Data;
using System.Windows;
using System.Threading;
public static object m_lockObject;
public static ObservableCollection<T> m_OC;
OC = new ObservableCollection<T>();
BindingOperations.EnableCollectionSynchronization(m_OC, m_lockObject);
Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Send,
new Action(() => {
BindingOperations.EnableCollectionSynchronization(m_OC, m_lockObject);
}));
lock (m_lockObject)
{
m_OC.Add(null);
}