Alex Rivera | Logout

GetMessage with a timeout

Asked 2012-06-02T22:08:01.343
23

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 it should terminate. As the second 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.

Edit
Report

1 Answer

-1

Yep. Try PeekMessage() instead. But I think this will not be full problem solving.

answered 2012-06-02T22:10:38.113

Your Answer