1
Vote

{"The calling thread cannot access this object because a different thread owns it."}

description

After I installed Visual Studio 2015 Update 2, I started receiving this exception when I attached with WPF Inspector.

Exception:
{"The calling thread cannot access this object because a different thread owns it."}

Code looks like this:
public void AddImportantSystemEvents(SystemEvent systemEvent)
    {
        ThreadPool.QueueUserWorkItem(_ =>
        {
            DispatchService.Invoke(() => _systemStatusDataCollection.Insert(0, systemEvent));
            OnPropertyChanged("SystemStatusDataCollection");  __<- exception happens here__
        }
        );
    }
Stack Trace:

at System.Windows.Threading.Dispatcher.VerifyAccess()
at System.Windows.DependencyObject.GetValue(DependencyProperty dp)
at System.Windows.Controls.ItemsControl.get_GroupStyleSelector()
at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.GetGroupStyle(CollectionViewGroup group, Int32 level)
at System.Windows.Controls.ItemContainerGenerator.PrepareGrouping()
at System.Windows.Controls.ItemContainerGenerator.RemoveAllInternal(Boolean saveRecycleQueue)
at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.RemoveAll()
at System.Windows.Controls.ItemContainerGenerator.OnRefresh()
at System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Windows.WeakEventManager.ListenerList1.DeliverEvent(Object sender, EventArgs e, Type managerType)
at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Controls.ItemCollection.OnViewCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Windows.WeakEventManager.ListenerList
1.DeliverEvent(Object sender, EventArgs e, Type managerType)
at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Data.ListCollectionView.RefreshOverride()
at System.Windows.Data.CollectionView.RefreshInternal()
at System.Windows.Data.CollectionView.Refresh()
at ChristianMoser.WpfInspector.UserInterface.Controls.PropertyItems.ListPropertyItem.BuildPropertyItemList()
at ChristianMoser.WpfInspector.UserInterface.Controls.PropertyItems.CompositePropertyItem.OnValueChanged(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.ComponentModel.PropertyDescriptor.OnValueChanged(Object component, EventArgs e)
at System.ComponentModel.ReflectPropertyDescriptor.OnValueChanged(Object component, EventArgs e)
at System.ComponentModel.ReflectPropertyDescriptor.OnINotifyPropertyChanged(Object component, PropertyChangedEventArgs e)
at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
at Prism.Mvvm.BindableBase.OnPropertyChanged(String propertyName)
at App.ViewModels.MainWindowViewModel.<>c__DisplayClass525_0.<AddImportantSystemEvents>b__0(Object _) in C:\alcs_v2\SCEEDSv2\UI\LaserControl\ViewModels\MainWindowViewModel.cs:line 1895
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

comments