Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 177563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:04:35+00:00 2026-05-11T14:04:35+00:00

I am trying to load an image in the background and then update the

  • 0

I am trying to load an image in the background and then update the UI. I have been playing with this all day and I don’t know what I am missing. I keep getting the following error:

‘The calling thread cannot access this object because a different thread owns it.’

I’ve hunted around following example after example, but I cannot seem to find an answer. I also wrapped the code that is touching the UI in another BeginInvoke.

Update 3: The moral of the story. ImageSource is not thread safe for access.

Update 2: This has got to be a simple solution :). I tried the cloning, but that didn’t result in success, but I did get a different error: ‘Exception has been thrown by the target of an invocation.’

Update 1: I tried the BackgroundWorker, but I am still getting the same error, but it is occurring on the brush.ImageSource.Height. Am I signaling the UI correctly? Any suggestions?

Here is my XAML:

<Window x:Class='Slideshow.Show' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>     <DockPanel>         <Canvas Background='Black' Name='canvas'>             <Viewbox Name='background' Stretch='Uniform'>                 <Rectangle name='background' />             </Viewbox>         </Canvas>     </DockPanel> </Window> 

Here is some of the code behind:

namespace Slideshow {     public class Show      {         public Show()         {             BackgroundWorker bw = new BackgroundWorker();             bw.DoWork += new DoWorkEventHandler(bw_DoWork);             bw.RunWorkerCompleted +=                  new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);             bw.RunWorkerAsync();         }          void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)         {             BitmapSource bitmap = e.Result as BitmapSource;              if (bitmap != null)             {                 this.Dispatcher.BeginInvoke(DispatcherPriority.Normal                      (ThreadStart)delegate()                 {                     Image image = new Image();                     image.Source = bitmap;                     background.Child = image;                  });             }         }          void bw_DoWork(object sender, DoWorkEventArgs e)         {             BitmapSource bitmapSource = CreateBrush(GetRandomFile());             e.Result = bitmapSource;          }     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:04:36+00:00Added an answer on May 11, 2026 at 2:04 pm

    What I tend to use the ThreadPool.QueueUserWorkItem to load the image, then when the operation completes I call back to the UI thread using the thread-safe Dispatcher object. The image source is not thread safe, you will have to use something like the JpegBitmapDecoder, there is also a PngBitmapDecoder.

    For Example:

    public Window() {     InitializeComponent();      ThreadPool.QueueUserWorkItem(LoadImage,          'http://z.about.com/d/animatedtv/1/0/1/m/simp2006_HomerArmsCrossed_f.jpg'); }  public void LoadImage(object uri) {     var decoder = new JpegBitmapDecoder(new Uri(uri.ToString()), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);     decoder.Frames[0].Freeze();     this.Dispatcher.Invoke(DispatcherPriority.Send, new Action<ImageSource>(SetImage), decoder.Frames[0]); }  public void SetImage(ImageSource source) {     this.BackgroundImage.Source = source; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load an image through PHP, but I don't know how. The
I am trying to load an image in memory but might have memory issues
Im loading an image from a SQL CE db and then trying to load
I'm trying to have a background image on an image control in WPF, such
I'm trying to use threading to load an image from a url. I have
I've been trying to set a background image on a gtk widget without success,
I have an image that I'm trying to load in IE9. I can get
Im trying to load a image at runtime in WPF using the following code
I am trying to load the image in the following way. But when I
I'm trying to load an image slider via AJAX. When typing in the direct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.