Suppose I have a one-time event that should be incremented after X seconds, for example, a timeout. Intuitively, it would be wise to create System.Timers.Timer, set its interval to X * 1000, lay its mark before the event, and start it. Since this is a recurring event, and you want it to be raised as soon as you would need to stop the timer after it is clicked.
The fact that timers inherently repeat itself nevertheless makes me incredulous if this is really the best way to do this. Would it be better / more accurate / safer to save the start time, set the timer to a mark every second (or even a millisecond) and tick the system for a while and manually raise the target event only after the required time has elapsed?
Can anyone weigh what is the best method (maybe there is another option that I didn’t think about either). Is one method better than the other if the wait time I need to wait is measured in milliseconds?
source
share