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 ) );
}
source
share