However, you are still unable to interrupt executable code. The code itself should provide the ability to cancel itself, which the timer could call after a certain time.
You can use the logical "shouldCancel", for example, which you check at each iteration of your loop (or even several times).
The "bad" way would be to use Thread.Abort - however this is not a very good style.
source
share