title: Mixing async/await with Result
body: <p>Let me just preface this question with a few things:</p>
  
  <ol>
  <li>I've read several SO questions saying that you should <strong>not</strong> do this (such as <a href="https://stackoverflow.com/questions/24296325/how-to-safely-mix-sync-and-async-code">How to safely mix sync and async code</a>)</li>
  <li>I've read <a href="https://msdn.microsoft.com/en-us/magazine/jj991977.aspx" rel="nofollow noreferrer">Async/Await - Best Practices in Asynchronous Programming</a> again saying you shouldn't do this</li>
  </ol>
  
  <p>So I do know that this is not a best practice, and don't need anyone telling me such.  This is more of a "why does this work" question.</p>
  
  <p>With that out of the way, here is my question: </p>
  
  <p>I've written a small GUI application that has 2 buttons and a status label.  One of the buttons will reproduce the deadlock issue with sync and async 100% of the time.  The other button calls the same async method but it is wrapped in a Task, this one works.  I know this is not a good coding practice, but I want to understand <strong>why</strong> it doesn't have the same deadlock issue.  Here is the code:</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      private async Task&lt;string&gt; DelayAsync()
      {
          await Task.Delay(1000);
          return "Done";
      }
  
      private void buttonDeadlock_Click(object sender, EventArgs e)
      {
          labelStatus.Text = "Status: Running";
  
          // causes a deadlock because of mixing sync and async code
          var result = DelayAsync().Result;
          // never gets here
          labelStatus.Text = "Status: " + result;
      }
  
      private void buttonWorking_Click(object sender, EventArgs e)
      {
          labelStatus.Text = "Status: Running";
          string result = null;
  
          // still technically mixes sync and async, but works, why?
          result = Task.Run(async () =&gt;
          {
              return await DelayAsync();
          }).Result;
  
          labelStatus.Text = "Status: " + result;
      }
  }
  </code></pre>