在我的应用程序中,我需要检查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
事件仍在执行?
答案 0 :(得分:0)
我终于设法通过一个较小的示例重现了该问题-事实证明,这是第三方组件(Syncfusion)中的错误。
我已经联系支持部门寻求帮助