Imagine I have a program which has a big ammount of functions and procedures with a lot of loops.

Then I want to add four buttons:
  • One to Start the process of my program (is an algorithm which takes minutes)
  • Another one to Stop the process of my algorithm.
  • Another one to Pause my process of my algorithm.
  • And the last one to Resume the process of my algorithm wherever it has been stopped after.


I thought adding a variable in each loop to test if the algortihm has to continue is not the best way to do it.
And I'm afraid by this way I can't also Pause/Resume the algorithm, only Stop it, obviusly.

Any idea to do it?