title: Is there a way to be notified when Task.Status changes to running?
body: <p>I'm writing a class that runs tasks and notifies based on <a href="https://msdn.microsoft.com/en-us/magazine/dn605875.aspx" rel="nofollow">this</a>.</p>
  
  <p>One problem I can't think of a solution for is how to notify when Task.Status goes from <code>TaskStatus.WaitingForActivation</code> to <code>TaskStatus.Running</code>.</p>
  
  <p>Shortened code below:</p>
  
  <pre><code>using System.ComponentModel;
  using System.Runtime.CompilerServices;
  using System.Threading.Tasks;
  
  public abstract class ExecutionTracker : INotifyPropertyChanged
  {
      protected ExecutionTracker(Task task)
      {
          Task = task;
          AwaitTask(task);
      }
  
      public event PropertyChangedEventHandler PropertyChanged;
  
      public Task Task { get; }
  
      public TaskStatus Status =&gt; Task.Status;
  
      protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
      {
          PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
      }
  
      private async void AwaitTask(Task task)
      {
          try
          {
              // This is where status goes from WaitingForActivation to Running
              // and I want to do OnPropertyChanged(nameof(Status)) when it happens.
              // A hack would be setting a flag awaiting = true here and return TaskStatus.Running if the flag is true.
              // ^ feels nasty
              await task.ConfigureAwait(false);
          }
              // ReSharper disable once EmptyGeneralCatchClause We don't want to propagate errors here. Just make them bindable.
          catch
          {
          }
  
          // Signal propertychanges depending on result
      }
  }
  </code></pre>