My WinForm application contain many loops that takes time to complete, and many times when I click the X to close the form (and the application) I can see that the application is still running in the background, and I also see it in the Task-Manager.
What is the best way to exit all loops and threads in a clean way when the user is closing the main form?
Should I plant:
if (userPressedClose == true)
break;
in every loop and thread that I have in my application? It looks to me like an ugly solution…
Is there a simple way to ask the application to stop all loops and threads automatically, and end the application in a clean way?