I have a modelless dialog that creates a thread, and if the cancel button in the dialog is hit, a variable bCancel is set which the thread in question periodically checks, and then immediately jumps to its clean up code. It works fine. I can even send a WM_COMMAND...ID_CANCEL to the dialog from other places and it works the same. But its not working when I try to send ID_CANCEL to the dialog from the main application window's WM_CLOSE handler (i.e. the user is trying to shut the entire application down while this thread is running.) As best I can tell something is just terminating the thread from outside before it can execute its cleanup code. Does this sound right. What can I do.
(There's a critical section in the dialog's ID_CANCEL handler I didn't mention - not sure how relevant it is. (bCancel is set within this critical section and the thread executes its clean up code within the same critical section.)