title: What would be the difference between using the await keyword vs. the Task.Wait() method on a CPU bound task?
body: <p>What would be the <em>mechanical</em> difference between?</p>
  
  <pre><code>async void LongIOBoundWorkWithSomeCPUBoundWorkAsWellAsync()
  {
      await Task.Run(CPUBoundWork);
  
      // Do IO bound work
      await DoIOAsync();
  }
  
  and
  
  async void LongIOBoundWorkWithSomeCPUBoundWorkAsWellAsync()
  {
      var cpuTask = Task.Run(CPUBoundWork);
  
      cpuTask.Wait();
  
      // Do IO bound work
      await DoIOAsync();
  }
  </code></pre>
  
  <p>I understand that logically, both would result in the same flow-of-control. Under both the cases, the <code>DoIOAsync</code> method would get called only after the <code>CPUBoundWork</code> task has completed execution.</p>
  
  <p>However, would there be a difference in terms of the scheduling of the CPU task in both the cases?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Please confirm if my uneducated rumination about the code above is correct.</p>
  
  <p>It is my understanding that <code>await</code> disassociates any affinity between the thread and the task that was being run on the thread. While this works great for I/O requests, since you now re-use an I/O thread that was blocked on a network driver, you <em>want</em> to maintain thread-affinity for CPU bound work.</p>
  
  <p>While await destroys this affinity, the <code>Wait()</code> method, I am not sure but purely guessing, simply waits for the task to complete. If the task has not yet begun, it executes it on the current thread. If, however, the task had already begun earlier, it blocks the current thread, putting the current thread on the wait queue, the next time the thread that was executing the task on which <code>Wait</code> is called comes around and finishes its work, it signals the waiting thread and the waiting thread continues. Therefore, thread-affinity for the task is maintained when calling <code>Wait</code>.</p>
  
  <p>Of course, all of this is mere speculation. I want someone to confirm it.</p>