I want a way to be able to schedule callbacks, I want to be able register lots of different callbacks at various times to a "Scheduler"-object. Something like this.
public class Foo
{
public void Bar()
{
Scheduler s = new Scheduler();
s.Schedule(() => Debug.WriteLine("Hello in an hour!"), DateTime.Now.AddHours(1));
s.Schedule(() => Debug.WriteLine("Hello a week later!"), DateTime.Now.AddDays(7));
}
}
The best way I can come up with for implementing the Scheduler is to have a timer running inside at a given interval and each time the interval has elapsed I check the registered callbacks and see if it's time to call them, if so I do. This is quite simple but has the drawback that you only get the "resolution" of the timer. Let's say the timer is set to tick once a second and you register a callback to be called in half a second it still may not be called for a whole second.
Is there a better way to solve this?