CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Location
    Toronto, Canada
    Posts
    91

    Posting close message to child thread from primary thread

    I tried to post WM_CLOSE message to child thread from primary thread using Postthreadmessage in a while loop and i am ensuring that child thread is killed using Getexitcodethread(this also in while loop).The problem is it works fine in Debug Mode but it fails in RELEASE mode why?.It will not come out of while loop of GetExitCodeThread.Can u correct my logic
    Nag


  2. #2
    Join Date
    Apr 1999
    Posts
    37

    Re: Posting close message to child thread from primary thread

    Hi,
    GetExitCodeThread will just return the exit code of the thread.At that point there is no surity that the child thread is dead.So after u post the quit message to the child thread,u can wait on it and when the wait returns ,u can be sure that the thread is no more.
    sample code:
    DWORD PrimaryThread(LPVOID)
    {
    HANDLE hChildThread;
    DWORD dwChildThreadId;
    while(1)
    {
    hChildThread=CreateThread(NULL,0,ChildThread,0,0,&dwChildThreadId)
    Do Stuff
    PostThreadMessage (dwChildThreadId,WM_QUIT,0,0);
    WaitForSingleObject(hChildThread,INFINITE);
    now the child thread is dead for sure
    }
    }

    DWORD ChildThread(LPVOID)
    {

    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured