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
890
XamPivotGrid crashes if do LoadCustomizations too frequently
posted

Hello,

  I have a XamPivotGrid and some layouts that I have saved. There are 4 buttons "Test1, Test2, Test4, Test30" which when clicked, which load the layouts that I have saved. I have noticed that when clicking very frequently between buttons, the application crashes. I have added a sample to reproduce this issue, you have to launch it and then click "furiously" between buttons. It might be a little bit difficult to reproduce, but if you keep doing it, the application will crash. This is quite awkard because if our project it occurs more often and when it crashes, it's unacceptable. Can you please check into this? Thanks a lot.

LoadCustomizationsCrashIfClickQuicklySampleForForum0927.zip
Parents
No Data
Reply
  • 29105
    Offline posted

    Hello,

    I reviewed the stack trace and the exception is telling us that "an item has already been added to the collection".

    This particular exception is thrown intentionally and there is no logic in our source code to stop a "loading frenzy" from happening, or to happen silently in other cases. In our particular case the load method would never add items more then once, hover there is no logic for this to ever be prevented. 

    May I ask why you require to change the layout very frequently?

    Although there isn't a viable solution we use the following code to have the exception occur less frequently:

    pivotGrid.DataSource.Rows.CollectionChanging += AreaItems_CollectionChanging;
        pivotGrid.DataSource.Columns.CollectionChanging += AreaItems_CollectionChanging;
        pivotGrid.DataSource.Filters.CollectionChanging += AreaItems_CollectionChanging;
        pivotGrid.DataSource.Measures.CollectionChanging += AreaItems_CollectionChanging;
    }

    private void AreaItems_CollectionChanging(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        AreaItemsCollection senderColl = sender as AreaItemsCollection;
        if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
        {
            foreach (var item in e.NewItems)
            {
                if (item is IComparable)
                {
                    foreach (AreaItemsCollection filtersCollection in senderColl.UniqueGroup.Collections)
                    {
                        foreach (IAreaItemViewModel areaMember in filtersCollection)
                        {
                            IComparable member = areaMember;
                            if (member != null && member.CompareTo(item) == 0)
                            {
                                senderColl.CancelCollectionChanging = true;
                            }
                        }
                    }
                }
            }
        }
    }

    Let me know if you have any questions.

Children