Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8021153

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:53:45+00:00 2026-06-04T21:53:45+00:00

I have an application which second thread calls GetMessage() in a loop. At some

  • 0

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.

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:53:47+00:00Added an answer on June 4, 2026 at 9:53 pm

    The easiest way is to just call UINT_PTR timerId=SetTimer(NULL, NULL, 1000, NULL) before calling GetMessage. It will post a WM_TIMER message to the calling thread every second, so the GetMessage will return promptly. Then, call KillTimer(NULL, timerId) to cancel it.

    UPDATE Sample code:

    BOOL GetMessageWithTimeout(MSG *msg, UINT to)
    {
        BOOL res;
        UINT_PTR timerId = SetTimer(NULL, NULL, to, NULL);
        res = GetMessage(msg);
        KillTimer(NULL, timerId);
        if (!res)
            return FALSE;
        if (msg->message == WM_TIMER && msg->hwnd == NULL && msg->wParam == timerId)
            return FALSE; //TIMEOUT! You could call SetLastError() or something...
        return TRUE;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an application that queries a web service I wrote (which returns
I have an network application which uses a select loop like this: bool shutdown=false;
I have an application running in CF8 which does calls to external systems like
I have an ASP.NET MVC web application that makes REST style web service calls
I have a thread that, when its function exits its loop (the exit is
I wrote multithreading application which connects to some email accounts from database per thread.
I have a Qt application that launches two threads from the main thread at
I have application which needs to use a dll (also written by me) which
I have an application which i try to dev with the sencha touch 2
I have an application which is having a dictionary returned from a webservice.and i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.