title: C# async and await not waiting for code to finish
body: <p>Why is the following <code>async</code> and <code>await</code> not working?  I am trying to learn this would like to understand what is wrong with my code.</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
  
          callCount();
  
      }
  
      static void count()
      {
          for (int i = 0; i &lt; 5; i++)
          {
              System.Threading.Thread.Sleep(2000);
              Console.WriteLine("count loop: " + i);
          }
      }
  
      static async void callCount()
      {
          Task task = new Task(count);
          task.Start();
          for (int i = 0; i &lt; 3; i++)
          {
              System.Threading.Thread.Sleep(4000);
              Console.WriteLine("Writing from callCount loop: " + i);
          }
          Console.WriteLine("just before await");
          await task;
          Console.WriteLine("callCount completed");
      }
  }
  </code></pre>
  
  <p>The program goes starts the count() method but drops out without completing it.  With the await task; statement I was expecting it to wait to complete all loops of the count() method (0, 1, 2, 3, 4) before exiting.  I only get "count loop: 0".  But it is going through all of callCount().  Its like await task isn't doing anything.  I want both count() and callCount() to run asynchronously and return to main when complete.</p>