title: Task.Wait doesn't wait for async method completion
body: <p>Here is the code:</p>
  
  <pre><code>static async Task Main(string[] args)
  {
      var t = new Task(async () =&gt; await AsyncTest());
      t.Start();
      t.Wait();
      Console.WriteLine("Main finished");
  }
  
  private static async Task AsyncTest()
  {
      Thread.Sleep(2000);
      await Task.Delay(2000);
      Console.WriteLine("Method finished");
  }
  </code></pre>
  
  <p>My expectation is that <code>t.Wait()</code> will actually wait for <code>AsyncTest</code> method completion and output will be:</p>
  
  <pre><code>Method finished 
  Main finished
  </code></pre>
  
  <p>In reality output has only <code>Main finished</code>. Wait() is completed right at the moment when you hit <code>await Task.Delay(2000)</code> inside AsyncTest. The same happens if you replace <code>t.Wait()</code> with <code>await t</code> / <code>await Task.WhenAll(t)</code> / <code>Task.WaitAll(t)</code>.</p>
  
  <p>The solution is to rewrite method to synchronous implementation or call Wait() directly on AsyncTest(). However, the question is why does it work in such strange way?</p>
  
  <p>P.S. It's a simplified version of code. I was trying to achieve deferred task execution. In reality Task object is created by one part of program and then later is executed by another part after some specific condition.</p>
  
  <p>UPD: Rewriting var <code>t = new Task(async () =&gt; await AsyncTest())</code> to <code>var t = new Task(()=&gt; AsyncTest().Wait())</code> also fixes the problem. Though I still don't quite understand why Task doesn't work correctly with async/await inside delegate.</p>