No, you don't need use a second thread. You can find other way. I can not remember the function name. The reason you can not stop because the cpu is busy with your loop computation and not receive the message from user interface. You can use one function to get some cpu time to look at the message quene to process it.