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
1240
Calling RefreshSortPosition from InitializeRecordEvent causes Stack Overflow
posted

Our code calls RefreshSortPosition() from the InitializeRecord event as suggested in forum threads http://ko.infragistics.com/community/forums/p/69543/353415.aspx#353415, http://ko.infragistics.com/community/forums/p/56087/288546.aspx#288546, and http://ko.infragistics.com/community/forums/p/69543/353333.aspx#353333

Recently, we started seeing stack overflows when the user sorts columns in the grid.  This stack overflow has been traced to the RefreshSortPosition() being called from the InitializeRecord event handler.  Looking at the RefreshSortPosition()’s remarks, it says:

Note: This method should not be called directly from within the Infragistics.Windows.DataPresenter.DataPresenterBase.InitializeRecordEvent.  If the method needs to be called from within this event, you should do so asynchronously using Dispatcher.BeginInvoke Infragistics.Windows.DataPresenter.RecordCollectionBase.RefreshSort()

I changed our code to perform the RefreshSort(), but this slows things down tremendously.  I then put the RefreshSortPosition() into a Dispatcher.BeginInvoke along with some logic to avoid it being called during a grid sort, as well as some recursion avoidance logic. 

// Don't do this if we are in the middle of a sort or in

// the middle of a load

if (!this.IsSorting && this.CanClose)

{

       // Avoid recursive calls

       System.Diagnostics.Debug.Assert(!m_bCallingRefreshSort);

       if (!m_bCallingRefreshSort)

       {

              Action action = new Action(() =>

              {

                     m_bCallingRefreshSort = true;

                     //r.Record.ParentCollection.RefreshSort();

                     r.Record.RefreshSortPosition();

                     m_bCallingRefreshSort = false;

 

              });

              this.Dispatcher.BeginInvoke(action);

       }

}

This seems to work.

Is this an acceptable solution, or should one never call RefreshSortPosition() from the InitializeRecordEvent?

Thanks

Dan