title: Task WaitAny condition
body: <p>I found some code that uses the Task.WaitAny condition.</p>
  
  <pre><code>Task&lt;int&gt;[] tasks = new Task&lt;int&gt;[3];
  
  tasks[0] = Task.Run(() =&gt; { Thread.Sleep(2000); return 1; });
  tasks[1] = Task.Run(() =&gt; { Thread.Sleep(1000); return 2; });
  tasks[2] = Task.Run(() =&gt; { Thread.Sleep(3000); return 3; });
  
  while (tasks.Length &gt; 0) {
      int i = Task.WaitAny(tasks);
      Task&lt;int&gt; completedTask = tasks[i];
  
      Console.WriteLine(completedTask.Result);
  
      var temp = tasks.ToList();
      temp.RemoveAt(i);
      tasks = temp.ToArray();
  }
  </code></pre>
  
  <p>The code works fine, the result is 2 1 3.</p>
  
  <p>When I tried to change the sleeping intervals</p>
  
  <pre><code>tasks[0] = Task.Run(() =&gt; { Thread.Sleep(2000); return 1; });
  tasks[1] = Task.Run(() =&gt; { Thread.Sleep(1000); return 2; });
  tasks[2] = Task.Run(() =&gt; { Thread.Sleep(1000); return 3; });
  
  while (tasks.Length &gt; 0) {
      int i = Task.WaitAny(tasks);
      Task&lt;int&gt; completedTask = tasks[i];
  
      Console.WriteLine(completedTask.Result);
  
      var temp = tasks.ToList();
      temp.RemoveAt(i);
      tasks = temp.ToArray();
  }
  </code></pre>
  
  <p>I got 1 2 3, despite task number two is the one with the smallest sleeping time and should be the one removed first.</p>
  
  <p>What is happening under the hood?</p>