views:

16

answers:

0

I have a background thread that refreshes image on the screen every 50 ms by changing the Image.Source property. The images being loaded are in sequence. However, I see some of them being skipped on the screen. For eg, it shows frame1, 2, 3, 5, 7, 8, 10, 13... I tried to dump the images being drawn in Draw() to another screen. It appears all images are passed to the Draw method in correct order and no images are missing.

Can anyone tell me why they are not rendered as they should be? Why the images aren't refreshed when the Source is updated?

Here is roughly the layout of my code:

ThreadStart(..)
{
    for(int i=0; i<100; i++)
    {
        byte[] buffer = LoadNextImage(i);
        Dispatcher.BeginInvoke( () => Draw(buffer) );
        Thread.Sleep(50);
    }
}

void Draw(byte[] imageBuffer)
{
  BitmapImage bmp = new BitmapImage();
  bmp.SetSource(new MemoryStream(imageBuffer));

  // I dumped bmp into another screen here and it's always correct.

  //TheImage is an Image control in the XAML
  TheImage.Source = bmp;
}