2013-04-26

A TimerWheel implementation in C# with flexible rescheduling

Recently we started a project that, among a lot of other stuff, required many objects to be scheduled (and rescheduled) for processing. Each of these objects could, potentially, require it's own interval; for example object A could be required to process each 10 seconds, object B could need an interval of 3600 seconds and object C could need to be processed each second. As long as there's a handful of objects, instantiating a timer for each object would be an option. But since our collection could grow to contain more than thousands of objects I felt that having a timer hanging around for each of those objects wasn't the best idea ever. This was just a gut-feel until I later stumbled upon a blog-post from one of my all-time favorite bloggers Raymond Chen. Although, apparently, it's okay to have many timers lying around I felt there had to be a more efficient way to solve my problem.