title: In threads, WaitForMultipleObjects never returns if set to INFINITE
body: <p>Let say I have three thread handles</p>
  
  <pre><code>HandleList[0] = hThread1;
  HandleList[1] = hThread2;
  HandleList[2] = hThread3;
  /*All the above are of type HANDLE*/
  </code></pre>
  
  <p>Before closing the application, I want the thread to get its task done. So I want to make app wait till thread completes.</p>
  
  <p>So I do,</p>
  
  <pre><code>WaitForMultipleObjects(3, HandleList, TRUE, INFINITE );
  </code></pre>
  
  <p>By this I'm able to make the thread, complete its task. But control never move to next line after the call to WaitForMultileObjects irrespective of all thread completing its task.</p>
  
  <p>If I use, some seconds instead of INFINITE, it comes to next line after that many secs, irrspective of whether thread completes its task or not.</p>
  
  <pre><code>WaitForMultipleObjects(3, HandleList, TRUE, 10000 );
  </code></pre>
  
  <p>My problem here is, I'm can't go for seconds, as I may not be sure whether the threads will complete its task with the given time.</p>
  
  <p>To list my problem in simple words, 
  I want all my thread to finish the task, before I close my app. How can I achieve it using WaitForMultipleObjects API?</p>
  
  <p><strong>EDIT:</strong> 
  <em>As per MSDN..</em></p>
  
  <p>dwMilliseconds 
  [in] Time-out interval, in milliseconds. </p>
  
  <ul>
  <li>The function returns if the interval elapses, even if the conditions specified by the bWaitAll parameter are not met. </li>
  <li>If dwMilliseconds is zero, the function tests the states of the specified objects and returns immediately. </li>
  <li>If dwMilliseconds is INFINITE, the function's <strong>time-out interval never elapses</strong>. </li>
  </ul>