I have a simple UI that has two buttons 'Start' and 'Stop'. When user clicks 'Start' I have to perform a lengthy operation so I launch a worker thread to keep UI responsive. Now if user clicks Stop I need to stop the operation asap.
One way to implement this is that the worker thread function checks for a bool bStop = false every second and if user clicks Stop we set bStop to true from the Stop button handler and the worker thread stops the current operation.
Another way is to kill the thread using its handle.
Is there any better ways to do it?