I have a thread that reads from my serial port and then writes the information to my active child window. The problem I am having is that If I close the child window the thread tries to write to it causing an error. I would like to know how can I kill the thread when I close the child window. I have set up my OnDestroy function to call the ExitInstance of the CWinthread derived class, but that does not stop the thread. What can I do?