title: Using async/await with Dispatcher.BeginInvoke()
body: <p>I have a method with some code that does an <code>await</code> operation:</p>
  
  <pre><code>public async Task DoSomething()
  {
      var x = await ...;
  }
  </code></pre>
  
  <p>I need that code to run on the Dispatcher thread. Now, <code>Dispatcher.BeginInvoke()</code> is awaitable, but I can't mark the lambda as <code>async</code> in order to run the <code>await</code> from inside it, like this:</p>
  
  <pre><code>public async Task DoSomething()
  {
      App.Current.Dispatcher.BeginInvoke(async () =&gt;
          {
              var x = await ...;
          }
      );
  }
  </code></pre>
  
  <p>On the inner <code>async</code>, I get the error:</p>
  
  <blockquote>
    <p>Cannot convert lambda expression to type 'System.Delegate' because it is not a delegate type.</p>
  </blockquote>
  
  <p>How can I work with <code>async</code> from within <code>Dispatcher.BeginInvoke()</code>?</p>