0

I'm trying to update the source of an image control on the UI of my WPF app.

The code runs in nano seconds when called from the UI thread. When I set the source from a background thread, it takes some 60 - 80 seconds to complete.

What is causing the delay? How do I speed it up?

This is how am changing the image source from the background thread:

this.Dispatcher.Invoke((Action)(() =>
{
    catImage.Source = new BitmapImage(new Uri(fullCatURLPath, UriKind.Absolute));
}));
Bosah Chude
  • 3,670
  • 2
  • 22
  • 22
  • Yes. In other words: Profile your application with visual studio and locate the hot spots. – Samuel Dec 18 '14 at 09:50
  • My understanding is that you need to [freeze](https://stackoverflow.com/questions/11710560/using-bitmapimage-created-on-threadpool-thread) a bitmap created on a background thread before using it on another thread. So, maybe give that a try? – dbc Dec 18 '14 at 09:56
  • 1
    Dispatcher.Invoke does not run anything in a background thread. It just executes the Action synchronously on the Dispatcher thread, i.e. the UI thread. See e.g. [this answer](http://stackoverflow.com/a/16041810/1136211) for how to load an image in a separate thread. – Clemens Dec 18 '14 at 10:09

0 Answers0