title: Observable.Timer(): How to avoid timer drift?
body: <p>In a C# (.NET 4.0) Application, I use the Reactive Extensions (2.0.20823.0) to generate time boundaries for grouping events into aggregate values. To simplify queries to the resulting database, these boundaries need to be aligned on full hours (or seconds in the example below).</p>
  
  <p>Using <code>Observable.Timer()</code>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>var time = DefaultScheduler.Instance;
  
  var start = new DateTimeOffset(time.Now.DateTime, time.Now.Offset);
  
  var span = TimeSpan.FromSeconds(1);
  
  start -= TimeSpan.FromTicks(start.Ticks % 10000000);
  start += span;
  
  var boundary = Observable.Timer(start, span, time);
  
  boundary.Select(i =&gt; start + TimeSpan.FromSeconds(i * span.TotalSeconds))
      .Subscribe(t =&gt; Console.WriteLine("ideal: " + t.ToString("HH:mm:ss.fff")));
  
  boundary.Select(i =&gt; time.Now)
      .Subscribe(t =&gt; Console.WriteLine("actual: " + t.ToString("HH:mm:ss.fff")));
  </code></pre>
  
  <p>You can see that the intended and the actual time of the timer ticks drift apart quite heavily:</p>
  
  <pre class="lang-none prettyprint-override"><code>ideal: 10:06:40.000
  actual: 10:06:40.034
  actual: 10:06:41.048
  ideal: 10:06:41.000
  actual: 10:06:42.055
  ideal: 10:06:42.000
  ideal: 10:06:43.000
  actual: 10:06:43.067
  actual: 10:06:44.081
  ideal: 10:06:44.000
  ideal: 10:06:45.000
  actual: 10:06:45.095
  actual: 10:06:46.109
  ideal: 10:06:46.000
  ideal: 10:06:47.000
  actual: 10:06:47.123
  actual: 10:06:48.137
  ideal: 10:06:48.000
  ...
  </code></pre>
  
  <p>I also make use of a <code>HistoricalScheduler</code> and of course I have no problems there. I can tolerate slight inaccuracies and I do not need to care about system clock changes. There are no heavyweight operations triggered by those Observables.</p>
  
  <p>Also, I know there is a lengthy discussion of RX timer drift problems in this <a href="http://blogs.msdn.com/b/rxteam/archive/2012/06/20/reactive-extensions-v2-0-release-candidate-available-now.aspx" rel="noreferrer">blog post</a>, but I don´t seem to be able to wrap my head around it.</p>
  
  <p>What would be the right way to periodically schedule an <code>Observable</code> without systematic timer drift?</p>