Click to See Complete Forum and Search --> : how do I know when a thread is completed?


June 2nd, 1999, 04:05 PM
Hi,

I'm using AfxBeginThread() to initiate a worker thread in my program. I want to initiate some action when this thread terminates. How can I detect whether the thread has been completed?

Thanks,

-Andrew

Harvey Hawes
June 2nd, 1999, 07:15 PM
Hi,

A couple of simple ways:

1) Use a CEvent, and signal it in the thread just before it finishes...
2) Send a message to the main thread from worker thread...

There is probably a "right" way to do this, but I use both of those...

HTH,

Harvey Hawes

Software Engineer
BioScience Analysis Software Ltd.

Masters Candidate
Cardiovascular/Respiratory Sciences
Faculty of Medicine
University of Calgary
Calgary, Alberta, Canada

muscicapa
June 2nd, 1999, 11:25 PM
another way is to use WaitForSingleObject() which can take a thread handle

lucich
December 9th, 1999, 09:34 AM
You have API called GetExitCodeThread(...).
Look it up ...

Sam Hobbs
December 9th, 1999, 12:40 PM
Search the knowledge base. The reason I am confident that that is a good idea is because I know that the two articles called "HOWTO: Detect All Program Terminations" and "Starting and Terminating Windows-Based Applications" are worth looking at.