This is not an urgent nor important question, seems more like exercise.
How to run a function at a specific moment? The more precise, the better.
For instance, I have a method which says time. I want to run it on XX o'clock, XX:15:00 (and preferably, 000 ms), XX:30:00.000, XX:45:00.000.
Currently I have an (almost endless) loop, which checks DateTime.Now, calculates the TimeSpan to sleep for, sleeps for that inverval – 30 s (if that interval is bigger), sleeps again the same way, then calls the function.
The side-effect of this approach is stand-by mode. It seems that OS does not decrease the amount of sleeping time after waking up, so that when my laptop goes standby at XX:01, wakes up at XX:13, the thread will still be asleep, and therefore miss the XX:15:00.000 moment.
Maybe there is an easier way to say "call this function at XX:00:00.000" precisely.