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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:49:45+00:00 2026-05-23T11:49:45+00:00

So, the code goes somehow like this: MAIN(){ /*waiting window class declaration*/ threadinfo* oThread=new

  • 0

So, the code goes somehow like this:

MAIN(){
/*waiting window class declaration*/
    threadinfo* oThread=new threadinfo(); //An object that will help me know when to finish the thread
    QueueUserWorkItem((LPTHREAD_START_ROUTINE)waitingWindow, (void*)mThread, WT_EXECUTELONGFUNCTION);
    function_that_takes_time();
    oThread->setTerminated(); //set member terminated to bool true
/*continue with other things*/
}

and waitingWindow function that will run on that thread

MSG msg;
hwndWaiting=CreateWindow(...) // here the window is created
while (msg.message != WM_QUIT)
    {
        if (PeekMessage(&msg, null, 0U, 0U, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            if(oThread->isTerminated()) // isTerminated returns bool true if terminated
            {
                delete oThread;
                ExitThread(0);
            }
        }
    }
ExitThread(0);

Is ExitThread a good way to remove the waiting window, and safely remove the thread? (at least I’m 100% sure this way when to end it).

I’m asking this because this works nice in Windows XP, but will crash with “the application has stopped working” on Windows 7.

Thanks for the help.

  • 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-23T11:49:45+00:00Added an answer on May 23, 2026 at 11:49 am

    The best way to end threads in general, is to let them “gracefully” finish up by themselves. You could tell the thread to end by setting an event, for example:

    HANDLE hevent_die = CreateEvent(...);  
    HANDLE hthread_something = CreateThread(...); // or _beginthread()
    ...
    
    DWORD WINAPI thread_func (LPVOID param)
    {
      while(working && WaitForSingleObject(hevent_die, 0)!=WAIT_OBJECT_0)
      {
        ...
      }
    
      return 0;
    }
    
    
    while (msg.message != WM_QUIT)
    {
       ...
    
       if(WaitForSingleObject(hthread_something, 0) == WAIT_OBJECT_0)
       {
         // do things if needed
       }
    }
    
    SetEvent(hevent_die);
    WaitForSingleObject(hthread_something, INFINITE);
    
    CloseHandle(hthread_something);
    CloseHandle(hevent_die);
    hthread_something = 0;
    hevent_die = 0;
    

    If you are using nested loops inside the thread function, they too will have to end if they receive the event.

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

Sidebar

Related Questions

Part of my code goes like this: while(1){ my $winmm = new Win32::MediaPlayer; $winmm->load('1.mp3');
The code goes something like this: protected bool IsOKToSend() { bool IsOK = true;
I like my code formatted like this: WithDataContext.Execute( delegate(DataContext dataContext) { // code goes
I have a code that goes something like: $cipher_alg = MCRYPT_RIJNDAEL_128; $decrypted_string = mcrypt_decrypt($cipher_alg,
I have a dataset obtained from MySQL that goes like this: Array ( [0]
So I understand that if I have to place this code $(#MyButton).click(function(){/* code goes
Right, this code goes through a rather large multidimensional array (has about 28,000 rows
I am getting time out from using JsonpRequestBuilder. The entry point code goes like
So, let's say I have this code (VB.Net): Sub Main() dim xxx as string
I have this strange problem I need some help with. This menu code goes

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.