Store the dialog HWND in a global variable, or kill the thread.
"Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C