title: Is my understanding of async/await, how it works and its benefits, correct?
body: <p>I've asserted my understanding of async/await on a couple of occasions, often with some debate as to whether or not I'm correct.  I'd really appreciate it if anyone could either confirm or deny my understanding, and clear up any misconceptions so that I don't spread misinformation.</p>
  <h1>High-Level Understanding</h1>
  <p><code>async</code>/<code>await</code> is a way of avoiding callback hell while writing asynchronous code.  A thread that is executing an asynchronous method will return to the thread pool when it encounters an <code>await</code>, and will pick up execution once the awaited operation completes.</p>
  <h1>Low-Level Understanding</h1>
  <p>The JIT will split an asynchronous methods into discrete parts around <code>await</code> points, allowing re-entry into the method with method's state preserved.  Under the covers this involves some sort of state machine.</p>
  <h1>Relation to Concurrency</h1>
  <p><code>async</code>/<code>await</code> does not imply any sort of concurrency.  An application written using <code>async</code>/<code>await</code> could be entirely single-threaded while still reaping all the benefits, much the way that node.js does albeit with callbacks.  Unlike node.js, .NET is multi-threaded so by having <code>async</code>/<code>await</code>, you get the benefits of non-blocking IO without using callbacks while also having multiple threads of execution.</p>
  <h1>The Benefits</h1>
  <p><code>async</code>/<code>await</code> frees up threads to do other things while waiting for IO to complete.  It can also be used in conjunction with the <a href="https://msdn.microsoft.com/en-us/library/dd460717(v=vs.110).aspx" rel="noreferrer">TPL</a> to do CPU bound work on multiple threads, or off the UI thread.</p>
  <p>In order to benefit from non-blocking IO, the asynchronous methods need to be built on top of API's that <em>actually</em> take advantage of non-blocking IO which are ultimately provided by the OS.</p>
  <h1>Misuse</h1>
  <p>This is the biggest point of contention in my understanding.  A lot of people believe that wrapping a blocking operation in a <code>Task</code> and using <code>async</code>/<code>await</code> will bring about a performance increase.  By creating an additional thread to handle an operation, returning the original thread to the thread pool, and then resuming the original method after the task completes, all that's occurring are unnecessary context switches while not really freeing up threads to do other work.  While this isn't as much a misuse of <code>async</code>/<code>await</code> as it is the TPL, this mindset seems to stem from a misunderstanding of <code>async</code>/<code>await</code>.</p>