Click to See Complete Forum and Search --> : Posting close message to child thread from primary thread


Cobra
May 27th, 1999, 05:16 AM
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

RajM
May 27th, 1999, 07:36 PM
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)
{

}