I have a thread that runs in a loop, and would like to kill a thread once a dialog that started the thread closes. What is the best way to do that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can call
interrupt()for the thread. This won’t stop the thread, however, unless you do something about it inside the thread loop.If you don’t want to use
interrupt()(say, you don’t have a reference to the thread), you can set a flag somewhere that is accessible to the thread code. You still need to check it in the thread loop and exit the loop (and therun()method) to exit the thread.