title: What would cause WaitForSingleObject with finite timeout not to return?
body: <p>The title says it all.  I am using C++ Builder to submit a form to an Internet server using TIdHTTP->Post(), to get a response.  Since that call can get stuck if there is a network problem or a server problem, I am trying to run it in a separate thread.  When the Post() returns, I signal the Event that I am waiting for with WaitForSingleObject, using a timeout of 1000.  At one point, I was processing messages after the timeouts, but now I am just repeating the WaitForSingleObject call with a timeout of 1000 again, until the event is signaled or my total timeout period (20 seconds) has elapsed.  If the timeout elapses, I would call Disconnect() on the TIdHTTP and try again.</p>
  
  <p>However, I have not been able to get this to work reliably, although it usually works.  I am using CodeSite to log the progress, and I can see that, on occasion, WaitForSingleObject is called, but does not return (ever).  Since WaitForSingleObject is being called on the main thread, the application is then unresponsive until it is killed.</p>
  
  <p>While one must always think of memory corruption when a C++ program stalls, I don't think that is what is going on.  The stall is always at the WaitForSingleObject call, and if it was a memory corruption issue, I would expect that, at least sometimes, something else would go wrong.</p>
  
  <p>The MSDN page for WaitForSingleObject says that the timer does not count down while the computer is asleep, and the monitor does go blank after a while, but the computer continues to run, and in any case WaitForSingleObject does not return once the mouse is moved and the monitor comes back on.</p>
  
  <p>So, again, my question.  What could be causing WaitForSingleObject with a finite timeout (1000 msecs) to never return?</p>