NotifyPropertyChangedOptimzation in PropertyChangedBase

Topics: UI Architecture
Jun 5, 2013 at 2:50 PM
Edited Jun 5, 2013 at 3:08 PM
In PropertyChangedBase I discovered following Code.
public virtual void NotifyOfPropertyChange([CallerMemberName] string propertyName = "")
    {
      if (!this.IsNotifying)
        return;
      Execute.OnUIThread((System.Action) (() => this.OnPropertyChanged(
           new   PropertyChangedEventArgs(propertyName))));
    }
I think this could be optmized into.
public virtual void NotifyOfPropertyChange([CallerMemberName] string propertyName = "")
    {
      if (!this.IsNotifying)
        return;
    if (PropertyChanged==null)
        return;

      Execute.OnUIThread((System.Action) (() => this.OnPropertyChanged(
           new   PropertyChangedEventArgs(propertyName))));
    }
So it tests if someone is listening and only then it fires the onpropertyChanged on UIThread.