Faulty NotifyPropertyChanged calls cause performance issues?

In my new WPF application, I am reusing the Model class. In this model class, all properties in their setters light up NotifyPropertyChanged. In my application, I really have no case of using INPC for individual ownership. I need to know that if I keep the current architecture, where individual properties start INPC every time they are changed, will it have any performance impact? Does it make sense to have individual properties to fire inpc when it is not needed?

+3
source share
4 answers

Generally speaking, anytime you use a piece of code that you don't need, you are potentially causing performance issues.

As a rule, when you write setters for your properties, and not just set your background field and raise a change event, you should check the equality before notifying, thereby avoiding unnecessary updates.

eg:

public int MyInteger 
{
   get { return this._myInteger; }
   set { 
         if ( value != this._myInteger )
         {
            this._myInteger = value;
            RaiseChangedEvent("MyInteger");
         }
      }

you should also check attached events in your methods RaiseChangedEvent, so if there are no listeners, you will not throw an exception with a null reference and you will not make an unnecessary call:

private void RaiseChangedEvent(string propertyName)
{
   var changedHandler = this.PropertyChanged ;
   if ( changedHandler != null )
      changedHandler(this, new PropertyChangedEventArgs( propertyName ) );
}
+5
source

If nothing is tied to the events for these objects, then there should not be a big penalty for performance, although you are still executing the code, and therefore there will be some difference compared to deleting it.

+1
source

PropertyChanged :

private void NotifyPropertyChanged(string name) {
    if (PropertyChanged != null) {
        PropertyChanged(this, new PropertyChangedEventArgs(name));
    }
}

PropertyChanged NULL, . , , , .

, , .

+1

INotifyPropertyChange - , , - ( ) , , , , , INotifyPropertyChange

0

All Articles