title: GetMessage with a timeout
body: <p>I have an application which second thread calls <code>GetMessage()</code> in a loop. At some point the first thread realizes that the user wants to quit the application and notifies the second thread that it should terminate. As the second thread is stuck on <code>GetMessage()</code>, the program never quits. Is there a way to wait for messages with a timeout?
  I’m open to other ideas too.</p>
  
  <p><strong>EDIT:</strong> (additional explanations)</p>
  
  <p>The second thread runs that snippet of code:</p>
  
  <pre><code>while ( !m_quit &amp;&amp; GetMessage( &amp;msg, NULL, 0, 0 ) )
  {
      TranslateMessage( &amp;msg );
      DispatchMessage( &amp;msg );
  }
  </code></pre>
  
  <p>The first thread sets <code>m_quit</code> to true.</p>