Re: how to end a thread from the main thread
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Fri, 23 Dec 2005 12:10:16 -0500
That would be silly. If I were doing that, I'd wait on the thread handle, because it is
more efficient (Sleep(10) will essentially push CPU utlization towards 100%). It has the
same set of problems, because it blocks the message pump.
joe
On Fri, 23 Dec 2005 11:16:44 +0100, Michael Nielsen <mnielsen@xxxxxxx> wrote:
>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?
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- 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
- Re: how to end a thread from the main thread
- From: Michael Nielsen
- how to end a thread from the main thread
- Prev by Date: Re: Adding external classes
- Next by Date: Deleting CObArray enteries
- Previous by thread: Re: how to end a thread from the main thread
- Next by thread: Opening a file through Explorer-co9ntext menu Open With...
- Index(es):
Relevant Pages
|