The ListChanged event is called too many times - Controls are very slow

The ListChanged event is called too many times - Controls are very slow

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


Arjun posted on Friday, June 07, 2013

Hi,

I have a Add/Edit screen, where the controls are bound to properties in a business base class. There are many business rules written to modify the control behaviour.

When any of the property is changed in the form, the gets are callled for every property in the class. And The Dependancy rule is observed to be calling the list changed event multiple times. If I remove the dependancy rules and run, the list changed event is calling only once. And on form load also list changed event is called many times.

As the List changed event is called multiple times, the UI seems to be slower than the usual behaviour. Could you please suggest some ideas to make the UI faster.

 

Thanks,

Arjun.

 

 

 

JonnyBee replied on Friday, June 07, 2013

Which version of CSLA do you use and which UI technology. 

If you use WindowsForms it is important to configure the PropertyChangedMode in app.config. as for CSLA 4 the default is Xaml. 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="CslaPropertyChangedMode" value="Windows" />
  </appSettings>
</configuration>


The thing to understand is that Windows Forms does a full refresh of bound controls on every PropertyChanged event. XAML does a refresh of only the specific property that has changed.

As yoiu can see from the code here in CSLA 4.5 this will also prevent OnPropertyChanged on the IsXYZ metastate properties.

    /// <summary>     /// Raises OnPropertyChanged for meta properties (IsXYZ) when PropertyChangedMode is not Windows     /// </summary>     /// <param name="name">meta property name that has cchanged.</param>
protected virtual void MetaPropertyHasChanged(string name)     {       if (ApplicationContext.PropertyChangedMode != ApplicationContext.PropertyChangedModes.Windows)         OnPropertyChanged(name);     }     /// <summary>     /// Check rules for the property and notifies UI of properties that may have changed.     /// </summary>     /// <param name="property">The property.</param>     [EditorBrowsable(EditorBrowsableState.Advanced)]     protected virtual void CheckPropertyRules(IPropertyInfo property)     {       var propertyNames = BusinessRules.CheckRules(property);       if (ApplicationContext.PropertyChangedMode == ApplicationContext.PropertyChangedModes.Windows)         OnPropertyChanged(property);       else         foreach (var name in propertyNames)           OnPropertyChanged(name);     }

Arjun replied on Wednesday, June 19, 2013

Hi JhonnyBee,

 

The CSLA version is 4.2.1.0 and We are using Windows forms - Dot.Net framework 4.0, tool Visual studio 2010.

 

Actually, The issue is that the screen is very slow. I have around 33 properties that are bound to 33 controls in the form. When I enter a character in the textbox, it is taking around 2 to 4 seconds to accept the next character input. I have tried the app setting key, it threw an error saying something like "The operation could not be completed as the file is used by someone else".

Any setting do u recommend to solve this issue ?

 

Thanks,

Arjun

 

JonnyBee replied on Wednesday, June 19, 2013

You must stop your application before you can edit the file. 

I am fairly certain this is part of your problem. 

Arjun replied on Thursday, June 20, 2013

Hi,

Yes, stopping the application and running it again worked.

But adding the key didnot change the speed of my form. Do you suggest something else ?

 

JonnyBee replied on Thursday, June 20, 2013

Hi,

Use a performance profiler to get insight into what is using time in your application. 

Visual Studio 2012 (Professional or higher)  has a built-in profiler.
Other options is the Redgate ANTS Profiler and JetBrains dotTrace products. 

tiago replied on Thursday, June 20, 2013

Arjun

When I enter a character in the textbox, it is taking around 2 to 4 seconds to accept the next character input.

Hi Arjun,

How is the DataBinding set? Are you using

a) DataSourceUpdateMode.OnPropertyChanged

or

b) DataSourceUpdateMode.OnValidation

According to your statement above, it looks like you are using OnPropertyChanged.

Did you try to use OnValidation?

JonnyBee replied on Friday, June 21, 2013

Hi,

One obvious possibility is the combination of updating the datas property with OnPropertyChanged and running synchronous rulers that does lookup/validation theat requires 2 to 4 seconds.

This will show up quickly in a performance profile.

Arjun replied on Saturday, June 22, 2013

Hi,

 

Yeah, I have tried OnValidation. With OnValidation, The business rules triggers only after the tab out which may not be intutive to the user. I was just trying to make the business rules to be triggered immediately when a character is entered.

And also, with OnValidation, the same lazy loading observed not for every character but on tab press.

 

JonnyBee replied on Saturday, June 22, 2013

Hi,

So does this mean that you do syncronous lazy loading of properties in your business object?

Arjun replied on Monday, June 24, 2013

Hi Jonny,

 

Yes exactly. Is this only because of the more number of properties?  In one of my previous applications, I have dealt with more number of controls in the screen, but the screen was fast enough. So, I guess, there is some project related setting or must be some difference in the way the object is created first.

 

Thanks,

Arjun

Copyright (c) Marimer LLC