Re: Terminating a worker thread
- From: "Allan Phillips" <allanephillips@xxxxxxxxx>
- Date: Tue, 5 Sep 2006 11:02:58 -0400
That worked just fine! Thanks.
"Chris Becke" <chris.becke@xxxxxxxxx> wrote in message
news:e1NVZ6L0GHA.1252@xxxxxxxxxxxxxxxxxxxxxxx
"Allan Phillips" <allanephillips@xxxxxxxxx> wrote in message
news:eP$lA1E0GHA.5048@xxxxxxxxxxxxxxxxxxxxxxx
I have created a second thread from my CDoc class that does somebackground
processing.
Everything seems to work fine unless I destroy the document before the
second thread has finished and exited.
I would like to kill my worker (second) thread as part of my document
destructor. What do I need to do to have that happen?
This depends on how you tell your worker thread what to do. Windows cannot
cleanly kill worker threads for you, they have to terminate properly so
that
objects get cleaned up, etc.
So, whatever the worker thread is stuck doing, you need to signal it to
abort its operation, and exit.
For example in my application I use a worker thread that i post thread
messages to. The worker thread therefore has a message pump. To destroy
the
worker thread I use the following code:
PostThreadMessage(dwThreadId,WM_QUIT,0,0);
WaitForSingleObject(hThread,INFINITE);
The first line tells the worker thread to terminate when it gets back to
the
message pump. The next line tells my main thread to wait, until the worker
thread has actually been destroyed.
.
- References:
- Terminating a worker thread
- From: Allan Phillips
- Re: Terminating a worker thread
- From: Chris Becke
- Terminating a worker thread
- Prev by Date: Re: High Avg. Disk Queue Length - Memory Mapped File
- Next by Date: Re: Application priority
- Previous by thread: Re: Terminating a worker thread
- Next by thread: Re: High Avg. Disk Queue Length - Memory Mapped File
- Index(es):
Relevant Pages
|