title: ASP.NET deadlock despite ConfigureAwait(false)
body: <p>EDIT: I have now solved the issue by simply marking the button click handler as async void and awaiting the task. I thought WebForms couldn't deal with async in any way except when used with RegisterAsyncTask. While this solves my problem, I am still interested in why the code below deadlocks since it goes against my current understanding of how asynchronous C# code works, so answers are still appreciated.</p>
  
  <p>I have a service exposing an async method that sends a request to some api. This method is consumed in a webforms codebehind. I understand that ASP.NET only allows one thread to execute at a time, so calling Task.Wait() causes a deadlock since the awaited task can't resume execution when completed since the context thread is blocked.</p>
  
  <p>It is however my understanding (from reading <a href="http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html" rel="nofollow">this blog</a>) that calling <code>ConfigureAwait(false)</code> on the awaited task causes the task to run on a thread pool thread instead, and therefore execution on the context thread can resume. I still get a deadlock from the code below though. Why is this?</p>
  
  <pre><code>protected void Activate(object sender, CommandEventArgs e)
  {
      var someID = int.Parse((string) e.CommandArgument);
      DoAsyncThingWithID(someID).Wait();
  }
  
  private async Task DoAsyncThingWithID(int ID)
  {
      try
      {
          await new SomeService()
              .DoSomeAsyncWork(ID)
              .ConfigureAwait(false);
      }
      catch (AppropriateException e)
      {
          DealWithIt();
      }
  }
  </code></pre>
  
  <p>Might be of note: DoSomeAsyncWork(int) has more async methods "under" it. Right at the bottom there is an api wrapping object (responsible for sending the HTTP request) with a method that is NOT async, but which is invoked with <code>Task.Run(() =&gt; api.SendThingy());</code></p>
  
  <p>Could this be the issue?</p>