Exiting threads safely

Hi list: 
I am in a situation wher i am creating threads in a com server. The
threads use WaitForSingleObject to process cross process communication.
I need to exit these two created threads when --and only when an
application exits. is the safest way to do thi using a process finding
mechanism (I aleady have this in place anyway) or using a second event.
If the latter, can I use this in a while lop like the following:
while(WaitForSingleObject(hevent, infinite) !=0)
{
code if the thread isn't to exit--i.e wait on the first event.
} 
exit the thread using an ExitThread call.
Any help apreciated.
Sean.

Other related posts: