title: C# async await Task.delay in Action
body: <p>I'm having some trouble getting a task to asynchronously delay.  I am writing an application that needs to run at a scale of tens/hundreds of thousands of asynchronously executing scripts.  I am doing this using C# Actions and sometimes, during the execution of a particular sequence, in order for the script to execute properly, it needs to wait on an external resource to reach an expected state.  At first I wrote this using Thread.Sleep() but that turned out to be a torpedo in the applications performance, so I'm looking into async/await for async sleep.  But I can't get it to actually wait on the pause!  Can someone explain this?</p>
  <pre><code>static void Main(string[] args)
      {
          var sync = new List&lt;Action&gt;();
          var async = new List&lt;Action&gt;();
  
          var syncStopWatch = new Stopwatch();
          sync.Add(syncStopWatch.Start);
          sync.Add(() =&gt; Thread.Sleep(1000));
          sync.Add(syncStopWatch.Stop);
          sync.Add(() =&gt; Console.Write(&quot;Sync:\t&quot; + syncStopWatch.ElapsedMilliseconds + &quot;\n&quot;));
  
          var asyncStopWatch = new Stopwatch();
          sync.Add(asyncStopWatch.Start);
          sync.Add(async () =&gt; await Task.Delay(1000));
          sync.Add(asyncStopWatch.Stop);
          sync.Add(() =&gt; Console.Write(&quot;Async:\t&quot; + asyncStopWatch.ElapsedMilliseconds + &quot;\n&quot;));
  
          foreach (Action a in sync)
          {
              a.Invoke();
          }
  
          foreach (Action a in async)
          {
              a.Invoke();
          }
      }
  </code></pre>
  <p>The results of the execution are:</p>
  <blockquote>
  <p>Sync:   999</p>
  <p>Async:  2</p>
  </blockquote>
  <p>How do I get it to wait asynchronously?</p>