title: best way to use the nice .net 4.5 HttpClient synchronously
body: <p>I like the new System.Net.Http.HttpClient class. It has a nice simple API, it doesn't throw on normal errors. But its async only.</p>
  
  <p>I need code that goes (deep inside a server)</p>
  
  <pre><code>foo();
  bar();
  // compute stuff
  var x = GetThingFromOtherServerViaHttp();
  // compute more stuff
  wiz(x);
  </code></pre>
  
  <p>classic sequential synchronous code. I saw several SO question that were similar but never actually ended up saying 'do this'. I looked at</p>
  
  <pre><code>client.PostAsync.Wait()
  </code></pre>
  
  <p>the world screams 'dont do this'. How about:</p>
  
  <pre><code>client.PostAsync.Result()
  </code></pre>
  
  <p>isnt this just Wait in disguise?</p>
  
  <p>In the end I ended up passing in a lambda callback that processed the result and then awoke the calling thread that was explicitly waiting on a EventWaitHandle. A lot of plumbing. Is there something a little simpler or shoul I just go back to using the old http clients</p>
  
  <p>EDIT:After further reading I suspect that this code has the same issues as Wait and Result, its just a more longwinded deadlock</p>
  
  <p>EDIT: I had MS PM confirm to me recently that there is a mandate 'any API that might take > X ms (I forgot X) must be async', many PMs interpret this as 'async only' (not clear if this is what is intended). Hence the Document DB api being only async.</p>