MVVM DoCancel slow

MVVM DoCancel slow

Old forum URL: forums.lhotka.net/forums/t/8651.aspx


Kevin Fairclough posted on Friday, March 12, 2010

Hi

Csla 3.8.0, WPF with MVVM.

I have a screen that is a master /detail using a TreeView control.  The treeview is bound to a childcollection which is recursive but only the first level is fetched.  The collection contains 568 elements.  If I alter the record either the header or the childcollection and undo it takes 8 seconds to cancel.

I have tried setting the datacontext of the root element to null before the cancel using events in the viewmodel but it still takes ages at the following point:

protected virtual void DoCancel()
        {
            if (ManageObjectLifetime)
            {
                var undo = Model as Csla.Core.ISupportUndo;
                if (undo != null)
                {
                    undo.CancelEdit();   // This call takes 8 seconds to complete
                    undo.BeginEdit();
                }
            }
        }

 

Any ideas?

TIA

Kevin

 

skagen00 replied on Friday, March 12, 2010

I ran into a problem where I was managing a large scale ObservableCollection, which is obviously not a CSLA object but I'm just guessing that maybe it's the same sort of property change events you're encountering.

For my 2000+ item collection, an operation that I was doing to the collection was causing a delay of 5 seconds or so.

I moved over to this, and it worked like a charm.

    public class MyObservableCollection<T> : ObservableCollection<T>
    {
        private bool _areEventsActive = true;
        public bool AreEventsActive
        {
            get { return _areEventsActive; }
            set
            {
                if (_areEventsActive != value)
                {
                    _areEventsActive = value;
                    if (_areEventsActive)
                    {
                        OnCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset));
                    }
                }               
            }
        }
      
        protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (_areEventsActive) base.OnCollectionChanged(e);
        }

        protected override void OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (_areEventsActive) base.OnPropertyChanged(e);
        }
    }

The "Reset" is for when a collection has changed dramatically.

Anyways, after making the change my operation is pretty instantaneous now.

Wonder if you could do some sort of similar notion. Just an idea.

Kevin Fairclough replied on Monday, March 15, 2010

Thanks for the reply.

There are definitely property changed events firing and causing this problem.  If I override and stop OnChildChanged on the Root and the Child and OnListChanged for the ChildList  then the Undo takes about 1 second.

I am using the standard Csla types, executing the standard DoCancel method.  I've also tried using a standard vanilla listbox with no templating instead of the treeview and it still takes 8 seconds to cancel.

Is there anyway around this using Csla 3.8.x?

TIA

Kevin

Copyright (c) Marimer LLC