Set the time and period of the timer to infinite to stop operations temporarily.
MyTimer.Change(Timeout.Infinite, Timeout.Infinite);
To resume the change, it reverts to the normal working interval:
MyTimer.Change(this.RestartTimeout, this.OperationInterval);
You do not need to delete and recreate it each time, and setting the interval to infinity will not waste time and additional processor cycles.
In this example, the value of this.RestartTimeout indicates how long until the first βtickβ of the timer this.RestartTimeout after resuming, I usually use 0.
In my specific use, I usually switch the time and period of the timer, and then stop the timer as the first line of its callback, do the timer work, and then resume it at the end. This is to prevent re-entry to the long code.
(Timeout.Infite - -1)
source share