title: Task.Delay() not behaving as expected
body: <p>Task.Delay() not behaving as expected or rather I'm not understanding what it is supposed to do. I'm trying to get my head around <code>Task</code>s in C# and how to replace <code>Thread</code>s in my implementation.</p>
  
  <p>What I'm trying to do is something like this: </p>
  
  <ul>
  <li>While true
  <ul>
  <li>print a line</li>
  <li>wait for a second,</li>
  <li>If condition is satisfied, exit loop, otherwise keep looping</li>
  </ul></li>
  </ul>
  
  <p>I've got that implemented with Threads fine, but all cool kids say I should be using Task, and don't touch Thread. </p>
  
  <p>So for the code I have this (Ignore <code>[Test]</code> - this just a convenient way to try out things)</p>
  
  <pre><code>    [Test]
      public void ChattyTask()
      {
          var chattyTask = new Task(ChattyWriter);
          chattyTask.Start();
          chattyTask.Wait();
      }
  
      public void ChattyWriter()
      {
          int count = 0;
          while (true)
          {
              var message = String.Format("Chatty Writer number {0}", count);
              Trace.WriteLine(message);
              count++;
              Task.Delay(1000);
  
              if (count &gt;= 20)
              {
                  break;
              }
          }
      }
  </code></pre>
  
  <p>When I run this, the test finishes in milliseconds, not in 20 seconds as I would expect. If I replace <code>Task.Delay()</code> with <code>Thread.Sleep()</code>, everything works as expected and I get the printout once a second. I have tried adding <code>async</code> and <code>await</code> into <code>ChattyWriter()</code>, but not only it did not add a 1 second delay, it only printed only one line instead of 20.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Probably It'll help to describe what I'm doing: my project works with external API (RESTful) and after I request some tasks to happen, I need to poll the API to check if the task has been completed. External tasks can be long running: 1-15 minutes. So I need some delay between checking for completion. And there could be many different concurrent processes executed with multiple external tasks. I understand, that if I use <code>Thread.Sleep()</code> when polling, other processes on the same <code>Thread</code> will be blocked for no good reason.</p>