wired exception from gridview possibly

3 posts, 0 answers
  1. hua
    hua avatar
    2 posts
    Member since:
    Apr 2015

    Posted 30 Apr Link to this post

    Hi Guys,

    My application uses gridview to hold latest 5000 records to be displayed, if new records is coming (per second), it will be added to index 0, and the oldest will be removed from ObservableCollection. Below are the sample codes:

    public ObservableCollection<EventHistory> ColDataSource {get;set;}

    private void Update(OnEventReportInput input)
    {                   
                    var history = new EventHistory();

                    ColDataSource.Insert(0, history);
                    if (ColDataSource.Count > 5000)
                    {                    
                        ColDataSource.RemoveAt(ColDataSource.Count - 1);
                    }
    }

    in most times, it works fine as my expected, but some times(randomly), my application is crashed caused by below excetion:

     

    2016-04-29 09:41:11,270 [1] ERROR Error - Application crashed | [InvalidOperationException] System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
       at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
       at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
       at System.Collections.Generic.List`1.Enumerator.MoveNext()
       at Telerik.Windows.Data.KeyedCollection.RefreshKeyDictionary()
       at Telerik.Windows.Data.KeyedCollection.IndexOf(Object value)
       at Telerik.Windows.Data.QueryableCollectionView.InternalIndexOf(Object item)
       at Telerik.Windows.Data.QueryableCollectionView.IndexOf(Object item)
       at Telerik.Windows.Data.Selection.ItemSelectionHandler.ScheduleForDeselectionAllNonExistentItems()
       at Telerik.Windows.Data.Selection.ItemSelectionHandler.DeselectAllNonExistentItems()
       at Telerik.Windows.Data.Selection.ItemSelectionHandler.HandleItemsReset()
       at Telerik.Windows.Data.Selection.ItemSelectionHandler.HandleItemsChanged(NotifyCollectionChangedEventArgs itemsChangedArguments)
       at Telerik.Windows.Controls.GridView.Selection.CompositeSelectionHandler.OnOwnerItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       at Telerik.Windows.Controls.GridView.Selection.CompositeSelectionHandler.<>c__DisplayClassa.<OnOwnerItemsCollectionChangedDispatch>b__8()
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

    2016-04-29 09:41:11,398 [1] ERROR Error - Application crashed | [InvalidOperationException] System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
       at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
       at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
       at System.Collections.Generic.List`1.Enumerator.MoveNext()
       at Telerik.Windows.Data.KeyedCollection.RefreshKeyDictionary()
       at Telerik.Windows.Data.KeyedCollection.IndexOf(Object value)
       at Telerik.Windows.Data.QueryableCollectionView.InternalIndexOf(Object item)
       at Telerik.Windows.Data.QueryableCollectionView.IndexOf(Object item)
       at Telerik.Windows.Data.Selection.ItemSelectionHandler.ScheduleForDeselectionAllNonExistentItems()
       at Telerik.Windows.Data.Selection.ItemSelectionHandler.DeselectAllNonExistentItems()
       at Telerik.Windows.Data.Selection.ItemSelectionHandler.HandleItemsReset()
       at Telerik.Windows.Data.Selection.ItemSelectionHandler.HandleItemsChanged(NotifyCollectionChangedEventArgs itemsChangedArguments)
       at Telerik.Windows.Controls.GridView.Selection.CompositeSelectionHandler.OnOwnerItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       at Telerik.Windows.Controls.GridView.Selection.CompositeSelectionHandler.<>c__DisplayClassa.<OnOwnerItemsCollectionChangedDispatch>b__8()
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(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.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at SevenSwords.Gui.App.Main()

     

    This crash occurs randomly per 3 or 4 hours, the only clue I could find from log is gridview,  hope can get help from your guys!  

    Thanks!

     

     

  2. hua
    hua avatar
    2 posts
    Member since:
    Apr 2015

    Posted 01 May Link to this post

    Anyone can give me any clue? thanks!
  3. UI for WPF is Visual Studio 2017 Ready
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 May Link to this post

    Hi Hua,

    What I could suggest based on the StackTrace is one of the following:
    1. Verify whether the item that is to be removed is selected or not and try deselecting it explicitly.
    2. Insert the items in another thread - in a dispatcher or through a background worker. 

    Please give those approaches a try and let me know how it went. 


    Regards,
    Maya
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top