Re: how to end a thread from the main thread
- From: Michael Nielsen <mnielsen@xxxxxxx>
- Date: Fri, 23 Dec 2005 11:16:44 +0100
Joseph M. Newcomer wrote:
The trick goes like this...
Suppose for this example I have a boolean, ThreadRunning, on behalf of a view. Also a boolean called closing. Both are initialized to false, and ThreadRunning is set to TRUE when the thread starts
void CMyView::OnClose()
{
if(ThreadRunning)
{
... initiate thread shutdown
closing = TRUE;
} CView::OnClose();
}
LRESULT CMyView::OnThreadFinished(WPARAM, LPARAM) { ThreadRunning = FALSE; if(closing) PostMessage(WM_CLOSE); return 0; }
Don't you need a variable isClosed and set it true as the last thing the thread does so the application can wait for it (while(!isClosed)Sleep(10);) to be closed before exiting?
.
- Follow-Ups:
- Re: how to end a thread from the main thread
- From: Joseph M . Newcomer
- Re: how to end a thread from the main thread
- References:
- how to end a thread from the main thread
- From: Mystique
- Re: how to end a thread from the main thread
- From: Josh McFarlane
- Re: how to end a thread from the main thread
- From: Joseph M . Newcomer
- Re: how to end a thread from the main thread
- From: Josh McFarlane
- Re: how to end a thread from the main thread
- From: Joseph M . Newcomer
- how to end a thread from the main thread
- Prev by Date: Re: Somthing about timers
- Next by Date: Re: mutual dependent DLLs and global variables
- Previous by thread: Re: how to end a thread from the main thread
- Next by thread: Re: how to end a thread from the main thread
- Index(es):