title: Virtualizing data access
body: <p>I am fetching some data locally, and the actual fetching process is very fast. Lets say that as a result I have a List after a couple of ms.</p>
  
  <p>When I bind some items control (Ex ListBox) to this data, it takes some time before the data is displayed on items control. For example, if I have 100 items in List, it will take approx 10 seconds for items to be displayed in ListBox. The more, the merrier.</p>
  
  <p>The main problem is in data displaying. Each item has a path to image. So, when Itemtemplate is executed, it shrinks the image to predefined size and display it. So the more CPU time for image shrinking, more time for UI to become responsive.</p>
  
  <pre><code>&lt;DataTemplate x:Key="itemTemplate"&gt;
    &lt;StackPanel&gt;
      &lt;Image Width="48" Height="48"&gt;
        &lt;Image.Source&gt;
          &lt;BitmapImage DecodePixelWidth="48" UriSource="{Binding ImagePath}" /&gt;
        &lt;/Image.Source&gt;
      &lt;/Image&gt;
    &lt;/StackPanel&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>In order to make UI responsive, I moved image decoding to be done on async thread, using Rx, and that works. However, since this is a vey simple project (single exe), I wold try to avoid using Rx just for this task. So, how can I do this without Rx?</p>
  
  <pre><code>list.ToObservable(Scheduler.Default)
              .Buffer(5)
              .ObserveOn(SynchronizationContext.Current)
              .Subscribe(data =&gt;
                  {
                      foreach (var item in data)
                          UIList.Add(item);
  
                  }, null, null);
  </code></pre>