Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
520
Strange NullRefException ins RecordManager
posted

Hi, 

I am binding my XamDataGrid to an observable collection. When there is a change, I switch to UI thread and post a collection change event. Sporadically, I have seen an exception deep inside RecordManager:

Exception Details

=================

System.NullReferenceException:Object reference not set to an instance of an object.

   at Infragistics.Windows.DataPresenter.RecordManager.ProcessQueuedChangeNotifications(Boolean calledFromDelayedChange)

   at Infragistics.Windows.DataPresenter.RecordManager.OnChangeNotification(Object sender, Object eventArgs, Boolean isReset)

   at Infragistics.Windows.DataPresenter.RecordManager.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e)

   at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list)

   at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)

   at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)

   at 

I don't know how to reproduce this and it happens frequently for a few users so could someone help me diagnose what went wrong? and how to avoid this? 

Thank you

Parents
No Data
Reply
  • 54937
    Offline posted

    Do you mean that you are switching to the UI thread and changing the collection there or are you just changing the collection on the background thread and only switching to the UI thread to send the change notification? If you are changing the collection on the background thread you can still cause race conditions (such as the intermittent exceptions you mention) because the grid or any other object with access to the collection could be accessing/manipulating/enumerating the collection while you are changing it on the background thread or even after you change it but before the change notification is sent. You really have to change the collection on the UI thread or keep a copy of the collection on the ui thread that isn't manipulated and have it synchronize itself with the changed collection when it gets the collection change notification on the UI thread.

Children