Take the 2-minute tour ×

Is it possible to implement a custom hardware-timer-based scheduler for reactive extensions? How would I even start, are there any good examples?

I have a hardware that can send me an accurate interrupt each millisecond. I would like to leverage it to create a more precise RX scheduler.


Thanks to the keywords from Asti's answer I found this blog post, which lead me to the discovery that I can implement a VirtualTimeScheduler<TAbsolute, TRelative>, since my hardware device provides me with absolute timestamps.

share|improve this question
Doesn't just implementing IObservable work for your device? –  kenny Dec 6 '12 at 12:25

1 Answer 1

up vote 4 down vote accepted

I'm not sure how accurately it would pan-out (deadline guarantees are difficult to make in GC'd systems), but here's how I might start off.

  • Start off with by implementing the IScheduler interface.

  • Internally, use the System.Reactive.Concurrency.SchedulerQueue<TAbsolute> class to maintain a prioritised queue of scheduled items. TAbsolute is the type of the absolute due time of each scheduled item, so it might be easier if you choose a numeric type closest to the one provided by your hardware.

  • By using a prioritised queue for items, you only have evaluate the whether the first item in the queue is due. You can probably cache the next due time and compare it on every interrupt.

  • Additionally, implement the ISchedulerPeriodic interface, which allows it to be more optimized towards recurring schedules.

Good luck!

share|improve this answer
Thanks for pointing me in the right direction. I described the final solution in my question. –  サモライ Dec 6 '12 at 16:35
@m0sa I had originally considered VirtualTimeScheduler, but I wasn't sure if it was performant enough to be used in real-time. It's usually used for replaying/testing. –  Asti Dec 6 '12 at 16:43
FYI we had no performance problems so far and scheduler implemented using the VirtualTimeScheduler and a hardware interrupt runs very accurately on a 5 millisecond interval. –  サモライ Mar 8 '13 at 9:10

Your Answer


