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

  • Home
  • SEARCH
  • 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 6194583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:19:15+00:00 2026-05-24T03:19:15+00:00

In one C++ application I have a window whose message loop runs in a

  • 0

In one C++ application I have a window whose message loop runs in a separate thread because the main thread is busy calculating and rendering a simulation. The window acts as a log window for the simulation. When the simulation throws an exception, the simulation closes and the log window displays the details.

Now the main thread should wait until the log window is closed. Since the message loop runs on a separate thread, I tried to

WaitForSingleObject(logwindow->thread, INFINITE);

from the main thread.

However, this seems to block the message pump and the log window freezes. So how do I correctly wait until a window is closed or a thread ends?

ED: The window is created on the main thread but runs on a different thread. I’ll go ahead and change it so it creates on the message loop thread too.

  • 1 1 Answer
  • 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-05-24T03:19:17+00:00Added an answer on May 24, 2026 at 3:19 am

    You have a few options.

    1. Run all the UI out of the main thread and get the worker thread to synchronize reporting back to the main thread to display, for example via PostMessage or SendMessage.
    2. Don’t wait at all and get the worker thread to post a message to the main thread when the worker is done.
    3. Use MsgWaitForMultipleObjects for your wait.

    To elaborate on MsgWaitForMultipleObjects, it’s a wait function that can be configured to return when messages arrive in the queue. Thus you can keep your message pump alive whilst also using a blocking wait in between processing queued messages.

    In pseudo-code you would write it like this:

    do
    {    
        WaitResult = MsgWaitForMultipleObjects(1, hThread, TRUE, INFINITE, QS_ALLEVENTS);
        if (WaitResult == MessageArrivedOnQueue) 
            PumpMessageQueue();
    } while (WaitResult != WaitHandlesSignaled)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed one window application in C# where i am creating one thread
hello i have created one windows application in c# .net and its working fine
I have two windows application, one is a windows service which create EventWaitHandle and
I have a windows forms application in .NET 3.5. There's one form with 20
I have a Windows application that has 2 Forms . From one form I
I have two window form applications written in C, one holds a struct consisting
In one of my first Cocoa applications I have just a single window with
We have an application that has one or more text console windows that all
Hai every one I am developing an windows application in which i have to
I have created two forms in my Windows Application. One Form acts as a

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.