Slow day at work, so i decide to write a small app to kill some time. It will basically be an app where the user can set a time and an action (shutdown, log off etc.).
My question is, whats the best way for my program to keep a track of time? One thing I could do is compare with DateTime.now every x seconds, but that gives me a margin of error of x seconds.
Can/should I create a stopwatch and have it ticking down. When it reaches 0, it fires an event?
You could create a timer, and set its interval to the amount of time between now and when the action should occur. Then, in the OnTick event handler, perform the action (and stop the timer).