.NET WPF, Set Bitmap – Must create DependencySource on same Thread as the DependencyObject error

In WPF when you try to assign a bitmap to a property that’s bound to a UI element from a worker thread you may get the following error:

 

“Must create DependencySource on same Thread as the DependencyObject”

 

A simple way around this problem without having to jump through hoops and dispatch to the UI thread is to just freeze the bitmap before assigning it, like this:

 


var bitmap = new BitmapImage(new Uri(CurrentImageFilePath));
bitmap.Freeze();
this.CurrentImage = bitmap;

 

I hope this helps someone who’s stuck with this annoying error!

 
3 replies
  1. DK
    DK says:

    Assume. You ended my 6hours research for async loading of Userprofiles.
    Never thought about problems including a bitmap image!
    Thank you very much!

Comments are closed.