title: How to implement async INotifyPropertyChanged
body: <p>I have a class with properties that are bound to my view. To keep my view up-to-date, I implement INotifyPropertyChanged and raise the event everytime some property changes.</p>
  
  <p>Now I got some heavy functions that freeze my application. I want to put them into a background task.</p>
  
  <p>First: here my current approach</p>
  
  <p>(e.g. on button click)</p>
  
  <pre><code>private async void HeavyFunc()
  {
      foreach (var stuff)
      {
          count += await Task.Run(() =&gt; stuff.Fetch());
      }
  
      if (count == 0)
          //...
  }
  </code></pre>
  
  <p>stuff class</p>
  
  <pre><code>public async Task&lt;int&gt; Fetch()
  {
      //network stuff
  
      RaisePropertyChanged("MyProperty");
  }
  
  public async void RaisePropertyChanged(string pChangedProperty)
  {
      await Application.Current.Dispatcher.BeginInvoke(
          System.Windows.Threading.DispatcherPriority.Normal,
          new ThreadStart(() =&gt;
          {
              PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(pChangedProperty);
          }
      );
  }
  </code></pre>
  
  <p>The code above gives an exception ("DependencySource" must be created in the same thread like "DependencyObject").</p>
  
  <p>AFAIK, you generally need to create a new thread and run it (while awaiting it). ´await Task.Run(...);´ should do this job.</p>
  
  <p>Since the PropertyChanged event directly influences the UI, calling it in the UI thread seems to be a good decision. This is why I call Dispatcher.BeginInvoke.</p>
  
  <p>What I don't understand: the exception above is caused when different threads are responsible for the data. But I explicitely calling the event on my UI-thread and the object should be created by the UI-thread too. So why do I get an exception?</p>
  
  <p>My main question is: How do I implement the events for the INotifyPropertyChanged interface generally to avoid or handle most of the async programming problems like above? What should be considered while constructing the functions?</p>