I have wpf application that run some math operations .
When Start button click i calculate some math, and return value to Gui .
every operation has some loop inside.
I want give the user Cancel click that stop all the calculate immediately.
I saw CancellationTokenSource, I need send via Start method the cancellationTokenSource, then when user click on Cancel I cancel the cancellationTokenSource , and on the operation I need to check if cancellationTokenSource is cancel.
that work for me, the problem is that I need put in every loop on my code(I have some) check if the cancellationTokenSource is cancel, then i need to return/throw exception every time.
That too ugly, is there another way to cancel this operation without check lot of time during the code if cancellationTokenSource is cancel?