title: WPF Dispatcher.InvokeAsync() strange behavior with async delegate
body: <p>If you have an async method, like the one below:</p>
  
  <pre><code>    private async Task DoAsync()
      {
          Console.WriteLine(@"(1.1)");
          Thread.Sleep(200);
          Console.WriteLine(@"(1.2)");
          await Task.Delay(1000);
          Console.WriteLine(@"(1.3)");
      }
  </code></pre>
  
  <p>and you call it asynchronously with Dispatcher:</p>
  
  <pre><code>        Console.WriteLine(@"(1)");
          await Application.Current.Dispatcher.InvokeAsync(DoAsync);
          Console.WriteLine(@"(2)");
  </code></pre>
  
  <p>The output you'll get will be:
  (1)
  (1.1)
  (1.2)
  (2)
  (1.3)</p>
  
  <p>If you use Dispatcher.BeginInvoke() and you'll wait for Completed event, the effect will be the same (which is expected):</p>
  
  <pre><code>        Console.WriteLine(@"(1)");
          var dispatcherOp = Dispatcher.BeginInvoke(new Func&lt;Task&gt;(DoAsync));
          dispatcherOp.Completed += (s, args) =&gt;
          {               
          Console.WriteLine(@"(2)");
          };
  </code></pre>
  
  <p>What we see here is that the await in DoAsync() method makes Dispatcher believe the operation ended.</p>
  
  <p>My question: is it a bug or a feature? Do you know any document that describes this behavior? I couldn't find anything.</p>
  
  <p><em>I'm not asking for a workaround.</em></p>