I would like to do some work every 5 seconds. When I speak every 5 seconds, I mean 00:00, 00:05, 00:10, 00:15, 00:20 according to the system clock. Not every 5 seconds from the start of the timer.
Is there a .net timer that can do this already - I can't find it?
I can think of two works around ...
Have a timer with a very high resolution and read the system clock of each timer event. Fire my work right after every whole 5 seconds.
Have a timer with a very high resolution and read the system clock of each timer event. Turn off the second timer, which has a resolution of 5 seconds immediately after each full 5 seconds.
I do not like any of the approaches - the first puts an unnecessary load on the processor (depending on how high the ratio is). The second method can drop in after a very long time. I don’t know if this is true or not.
source
share