title: When does 'await' immediately leave a method and when does it not?
body: <p>In programs utilizing async-await, my understanding is like this:</p>
  
  <ul>
  <li>an async method that IS NOT awaited will run in the background (?) and rest of the code will continue to execute before this non-awaited method finishes</li>
  <li>an async method that IS awaited will wait until the method finishes before moving on to the next lines of code</li>
  </ul>
  
  <p>The application below was written by me to check if the above statements are correct.</p>
  
  <pre><code>using System;
  using System.Threading.Tasks;
  
  namespace ConsoleApp3
  {
      class Program
      {
          static async Task Main(string[] args)
          {
              Console.WriteLine("Hello World!");
  
              DoJob();
  
              var z = 3;
  
              Console.ReadLine();
          }
  
          static async Task DoJob()
          {
              var work1 = new WorkClass();
              var work2 = new WorkClass();
  
              while (true)
              {
                  await work1.DoWork(500);
                  await work2.DoWork(1500);
              }
          }
      }
  
      public class WorkClass
      {
          public async Task DoWork(int delayMs)
          {
              var x = 1;
  
              await Task.Delay(delayMs);
  
              var y = 2;
          }
      }
  }
  </code></pre>
  
  <p>Here are some of my observations:</p>
  
  <ul>
  <li>The <code>DoJob();</code> call is not awaited. However, the debugger shows me that the code inside of DoJob is being executed, just as if it was a normal non-async method.</li>
  <li>When code execution gets to <code>await work1.DoWork(500);</code>, I would think "OK, so maybe now the <code>DoJob</code> method will be left and  <code>var z = 3;</code> will be executed? After all, 'await' should leave the method." In reality, it just goes into <code>DoWork</code> and doesn't leave <code>DoJob</code> - <code>var z = 3;</code> is still not executed.</li>
  <li>Finally, when execution reaches <code>await Task.Delay(delayMs);</code>, <code>DoJob</code> is left, and the <code>var z = 3;</code> is reached. After that, code after the <code>Delay</code> is executed.</li>
  </ul>
  
  <p>The things that I don't understand:</p>
  
  <ul>
  <li>Why does <code>await Task.Delay(delayMs);</code> leave the <code>DoJob</code> method, but <code>await work1.DoWork(500);</code> does not?</li>
  <li>I see that <code>DoJob</code> is executing normally. I thought it would be done in the background (maybe by one of the thread pool threads?). Looks like it could block the thread if it was some long-running method, am I right?</li>
  </ul>