title: Invoking OnPropertyChanged NOT on the UI Thread - Performance Degradation
body: <p>I've solved some problem with a slow UI update, and I want to hear an explanation why my code modification actually improved the performance. </p>
  
  <p>I develop a WPF application, MVVM Architecture.
  I have a property in the view model:</p>
  
  <pre><code>public DateTime MyDate
      {
          get
          {
              return _myDate;
          }
          set
          {
              _myDate= value;
              OnPropertyChanged()
              OnPropertyChanged(() =&gt; MyDateFormatted);
          }
      }
  </code></pre>
  
  <p>and the MyDateFormatted looks as follows:</p>
  
  <pre><code>public string MyDateFormatted
      {
          get { return _myDate.ToString("MMMM dd, yyyy"); }
      }
  </code></pre>
  
  <p>The setter of MyDate does NOT happen on the UI Thread.
  The getter of MyDateFormatted happens on the UI Thread, because, as I've read, WPF automatically marshals property changes to the UI thread. </p>
  
  <p><a href="https://stackoverflow.com/questions/590590/making-sure-onpropertychanged-is-called-on-ui-thread-in-mvvm-wpf-app">Making sure OnPropertyChanged() is called on UI thread in MVVM WPF app</a></p>
  
  <p>And indeed, the UI was updated, but very slowly.
  Once, I've manually attached the 
  OnPropertyChanged(() => MyDateFormatted);
  to the UI Dispacher, by surrounding it with the invoke:
  Application.Current.Dispatcher,
  the UI updates now as quickly as I wanted, and the performance has improved dramatically. Can you please explain why? Thank you!</p>