Well-designed multithreaded program for this case (synchronous long loop) must show some kind of progress dialog with "Stop" button (if this necessary). Program with DoEvents should also allow to stop the process. The simplest way in both cases is to show some modal dialog with progress bar. If Stop is an option, it should react on the Stop button, and ignore any other commands. Without Stop, this dialog must ignore any user activity. In both cases, Paint messages are handled and application must redraw itself.
Modal progress dialog automatically prevents any user interaction with its parent window, this solves the problem of unexpected commands.