title: Task.WaitAll - Not Waiting?
body: <p>I am trying to get my head around Task.WaitAll(..) in the Task Parallel Library.</p>
  
  <p>I am running a test using the following code to try to simulate two tasks, one that will run longer (10 seconds) than the specified amount of time to wait for (10,, and one to run less (3 seconds) than the specified amount of time to wait for. The specified amount of time is 5 seconds. The code I am using is the following:</p>
  
  <pre><code>Task&lt;int&gt;[] tasks = new Task&lt;int&gt;[]
  {
      Task.Factory.StartNew&lt;int&gt;(()=&gt;
          {
              Thread.Sleep(10000);
              return 1;
          }),
      Task.Factory.StartNew&lt;int&gt;(()=&gt;
          {
              Thread.Sleep(3000);
              return 2;
          })
  };
  
  TimeSpan timeSpan = new TimeSpan(0, 0, 5);
  Task.WaitAll(tasks,timeSpan);
  
  int[] results = new int[tasks.Length];
  for(int i = 0; i &lt; tasks.Length;i++)
  {
      Console.WriteLine(tasks[i].Result);
  }
  </code></pre>
  
  <p>As far as the timeSpan, I have also tried directly passing in 5000 instead of the timeSpan variable, but it is not working. I am getting the following output:</p>
  
  <pre><code>1
  2
  </code></pre>
  
  <p>I would expect to only get the following output because the other thread is executing longer than the expected amount of time to wait.</p>
  
  <pre><code>1
  </code></pre>
  
  <p>Am I misunderstanding this, or doing this test wrong?</p>