在我的应用程序中,我将需要检查ObservableCollection
现在是否在CollectionChanged
事件中,如果是,我将不会修改集合。
我需要这样做的原因是因为有时候我的应用程序会快速连续地添加或删除事件,即使在之前的CollectionChanged
事件完成之前,下一个修改事件已经到来。如果发生这种情况,那么我会得到一个
在CollectionChanged事件期间无法更改ObservableCollection
System: System.InvalidOperationException
Cannot change ObservableCollection during a CollectionChanged event.
at System.Collections.ObjectModel.ObservableCollection`1.CheckReentrancy()
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.System.Collections.IList.Add(Object value)
at Syncfusion.Data.CollectionViewAdv.CommitNew()
at Syncfusion.UI.Xaml.Grid.GridAddNewRowController.CommitAddNew(Boolean changeState)
at Syncfusion.UI.Xaml.Grid.GridSelectionController.ProcessSourceCollectionChanged(NotifyCollectionChangedEventArgs e, CollectionChangedReason reason)
at Syncfusion.UI.Xaml.Grid.GridModel.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at Syncfusion.Data.CollectionViewAdv.RaiseSourceCollectionChangedEvent(NotifyCollectionChangedEventArgs args)
at Syncfusion.Data.CollectionViewAdv.SourceNotifyCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
在这种情况下,我的应用程序可以拒绝后续修改事件以避免崩溃。
如何实际告诉以前的CollectionChanged
事件仍在执行?
我终于设法在一个小样本中重现了这个问题 - 事实证明这是第三方组件(Syncfusion)中的一个错误。
我已经联系了支持人员寻求帮助