title: Task.Delay bugged or am I doing something wrong?
body: <blockquote>
    <p>EDIT: I was doing something wrong. Problem was timing code execution with datetime objects and outputing miliseconds instead of totalmiliseconds.</p>
  </blockquote>
  
  <p>In short I have a new mvc4 project running on .net 4.5 with the following code in the homecontroller.</p>
  
  <pre><code>    public async Task&lt;ActionResult&gt; Index()
      {
          Int32[] Delays = new Int32[] { 1999, 500, 20 }; 
          List&lt;String&gt; result = new List&lt;String&gt;();
  
          var now = DateTime.Now;
  
          result.Add(String.Format("Started at: {0}", now.ToString("MM/dd/yyyy hh:mm:ss.fff tt")));
  
          //TAKE 1
          result.Add("Take 1");
          await Task.WhenAll(Delays.Select(async x =&gt; result.Add(await Slow(x, now, Array.IndexOf(Delays, x), "take 1"))));
  
          //TAKE 2
          result.Add("Take 2");
          var tasks = Delays.Select((x, i) =&gt; Slow(x, now, i, "take 2")).ToList();
          await Task.WhenAll(tasks);
          result.AddRange(tasks.Select(x =&gt; x.Result));
  
          return View(result);
      }
  </code></pre>
  
  <p>My Slow method looks like this... </p>
  
  <pre><code>    private async Task&lt;String&gt; Slow(Int32 ms, DateTime dt, int i, String take)
      {
          Response.Write(String.Format("[{3}][index:{0}][delay:{2}] pre sleep - {1} &lt;br /&gt;", i, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), ms, take));
  
          await Task.Delay(ms);
  
          Response.Write(String.Format("[{3}][index:{0}][delay:{2}] after sleep - {1} &lt;br /&gt;", i, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), ms, take));
  
          var delayedtime = DateTime.Now;
  
          var diff = delayedtime - dt;
  
          return String.Format("Slept for : [{2}]{0} miliseconds. diff was : {1}", ms, diff.Milliseconds, take);
      }
  </code></pre>
  
  <p>The output looks like this ...</p>
  
  <pre><code>[take 1][index:0][delay:1999] pre sleep - 06/21/2013 02:46:25.338 PM
  [take 1][index:1][delay:500] pre sleep - 06/21/2013 02:46:25.340 PM
  [take 1][index:2][delay:20] pre sleep - 06/21/2013 02:46:25.340 PM
  [take 1][index:2][delay:20] after sleep - 06/21/2013 02:46:25.368 PM
  [take 1][index:1][delay:500] after sleep - 06/21/2013 02:46:25.849 PM
  [take 1][index:0][delay:1999] after sleep - 06/21/2013 02:46:27.347 PM
  [take 2][index:0][delay:1999] pre sleep - 06/21/2013 02:46:27.347 PM
  [take 2][index:1][delay:500] pre sleep - 06/21/2013 02:46:27.347 PM
  [take 2][index:2][delay:20] pre sleep - 06/21/2013 02:46:27.347 PM
  [take 2][index:2][delay:20] after sleep - 06/21/2013 02:46:27.382 PM
  [take 2][index:1][delay:500] after sleep - 06/21/2013 02:46:27.861 PM
  [take 2][index:0][delay:1999] after sleep - 06/21/2013 02:46:29.359 PM
  
  Started at: 06/21/2013 02:46:25.336 PM
  Take 1
  Slept for : [take 1]20 miliseconds. diff was : 32
  Slept for : [take 1]500 miliseconds. diff was : 513
  Slept for : [take 1]1999 miliseconds. diff was : 11
  Take 2
  Slept for : [take 2]1999 miliseconds. diff was : 23
  Slept for : [take 2]500 miliseconds. diff was : 525
  Slept for : [take 2]20 miliseconds. diff was : 46 
  </code></pre>
  
  <p>I'm quite puzzled by the fact that the delay of 1999miliseconds reports that it finished after 5 miliseconds where as the other two delays seem to work just fine.
  I get this behaviour as soon as the delay parameter is above '999' miliseconds.</p>
  
  <p>My question is if I'm doing something wrong, if the Delay is responding to a configuration I'm not aware of or if the Method is bugged.</p>