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 6197631
In Process

The Archive Base Latest Questions

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

I have a thread like this: DWORD WINAPI message_loop_thread(LPVOID dummy) { MSG message; while

  • 0

I have a thread like this:

DWORD WINAPI message_loop_thread(LPVOID dummy) {
        MSG message;
        while (GetMessage(&message, NULL, 0, 0)) {
                TranslateMessage(&message);
                DispatchMessage(&message);
        }
}

And i start it with CreateThread:

DWORD thread_id;
CreateThread(0, 0, message_loop_thread, 0, 0, &thread_id);

This seems to work, but how can i correctly close this thread? Normally the thread is waiting for GetMessage so the thread is blocked i think.

Is there a good way to do this? I tried TerminateThread, but this hangs, and i think it’s not a good solution to stop the thread.

Has someone an idea?

best regards
Benj Meier

  • 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:51:21+00:00Added an answer on May 24, 2026 at 3:51 am

    The proper way is to post WM_QUIT to thread_id. You use PostThreadMessage() for this. In response, GetMessage returns 0, the while loop exits, and the function exits (incorrectly, you’re missing a return statement). When the toplevel function of a thread exits, the thread ends.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a thread function that looks something like this: DWORD WINAPI Thread_ProcessFile( LPVOID
Suppose i have pointer to a thread like this CWinThread *m_pThread = AfxBeginThread(StartThread, this,
I have a thread in java/Android like this: Handler handler = new Handler() {
I have a thread like this public class SMS { class Read implements Runnable
I have a thread that get I initialize like this: Utility.Log(1); myThread = new
I have a table with a code like this: <table cellpadding=6 rules=groups frame=no> <thead>
I've seen a number of examples that have a thread procedure that looks like
My Goal I would like to have a main processing thread (non GUI), and
I have a similar issue like here: http://social.msdn.microsoft.com/forums/en-US/biztalkgeneral/thread/87d5a6ec-04ee-4c6f-8267-f526ee105f0b I have an asp.net web page
I have a thread that needs to be executed every 10 seconds. This thread

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.