GetMessage with a timeout

Posted by qdii on Stack Overflow See other posts from Stack Overflow or by qdii
Published on 2012-06-02T22:08:01Z Indexed on 2012/06/02 22:40 UTC
Read the original article Hit count: 185

Filed under:
|
|

I have an application which second thread calls GetMessage() in a loop. At some point the first thread realizes that the user wants to quit the application and notifies the second thread that he should terminate. As the first thread is stuck on GetMessage(), the program never quits. Is there a way to wait for messages with a timeout? I’m open to other ideas too.

EDIT: (additional explanations)

The second thread runs that snippet of code:

while ( !m_quit && GetMessage( &msg, NULL, 0, 0 ) )
{
    TranslateMessage( &msg );
    DispatchMessage( &msg );
}

The first thread sets m_quit to true.

© Stack Overflow or respective owner

Related posts about c++

Related posts about Windows