title: C# WPF change ImageSource Image on Thread
body: <p>I'm trying to update an ImageSource with an image on runtime from a different thread then the main_UI one, but for some reason i keep getting: <br><code>The calling thread cannot access this object because a different thread owns it.</code><br>
  I have tried a few things:</p>
  
  <ul>
  <li><code>im_Cover.Dispatcher.Invoke(() =&gt; { if (im_Cover.Source != image) im_Cover.Source = image; });</code></li>
  <li><code>Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =&gt; { im_Cover.Source = image; }));</code></li>
  <li>Freezing the image (which was not possible). I tried to add a messagebox on the error and once the error showed up and I pressed OK, for some reason, the image did load.</li>
  <li>Tried using a custom downloadcompleted eventhandler which didn't even fire.</li>
  </ul>
  
  <p>Here's my code:</p>
  
  <pre><code>for (int i = 1; i &lt; correctArtist.images.Count; i++)
  {
  if (correctArtist.images[i].width &gt; correctArtist.images[biggest].width)
     biggest = i;
  }
  Image biggestImage = correctArtist.images[biggest];
  var imgUrl = biggestImage.url;
  
  image = new BitmapImage(new Uri(imgUrl));
  
  
  bool uiAccessCover = im_Cover.Dispatcher.CheckAccess();
  if (uiAccessCover)
  {
      im_Cover.Source = image;
  }
  else
  {
      //im_Cover.Dispatcher.Invoke(() =&gt; { if (im_Cover.Source != image) im_Cover.Source = image; });
      Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =&gt; { im_Cover.Source = image; }));
  }
  </code></pre>
  
  <p>And for some reason this: <code>lb_Song.Dispatcher.Invoke(() =&gt; { if ((string)lb_Song.Content != song) lb_Song.Content = song; });</code> does work.</p>
  
  <p>Any idea why it doesn't work, and how I can fix this?</p>