Here’s a complete example with a GUI which shows a progress and allows to start/stop it:
EDIT: Moved to