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.
The Quartz.Net library seems what you’re looking for. It is a very flexible, open source job scheduling library, with good tutorials. It seems to be actively maintained as well (latest release from May 2009)
With this library, you can schedule jobs with all kinds of scheduling patterns, among which “at a certain time of day (to the millisecond)” (see features of quartz.net)
I’m not sure whether it copes with the standby event however…