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

  • Home
  • SEARCH
  • 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 262595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:31:44+00:00 2026-05-11T22:31:44+00:00

I have some BitmapFrames created on a thread other than the main UI thread;

  • 0

I have some BitmapFrames created on a thread other than the main UI thread;
Sometime after they are created (and their creator thread finishes), I am trying to use them in the main thread, as sources to some Image controls.

BUT I am getting this InvalidOperationException: The calling thread cannot access this object because a different thread owns it.

Need some help, how can I access (and use) them from the main thread?

I don’t see how I can use Dispatcher.Invoke since the second thread is finished.

Thank you in advance.

  • 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. Editorial Team
    Editorial Team
    2026-05-11T22:31:45+00:00Added an answer on May 11, 2026 at 10:31 pm

    There are two things you have to ensure:

    1. Freeze the BitmapFrame by calling BitmapFrame.Freeze(). This turns the frame read-only, and makes it available to other threads.

    2. You may already be doing this: to let the UI thread know the frame is ready, use Dispatcher.Invoke, instead of setting the properties or calling the methods of UI objects directly.

    To answer Teodor’s question, freezing could fail if the BitmapFrame is still being changed. This seems to happen when you use BitmapFrame.Create(Uri). The following code appears to avoid the issue by using a decoder. In case you are creating your BitmapFrame differently, the general rule is that you have to let it finish initializing, downloading, decoding, or otherwise changing before you freeze it. Disconnect any bindings too.

    Window1.xaml

    <Window x:Class="BitmapFrameDemo.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Window1" Height="300" Width="300">
        <Grid>
            <Image Name="image"/>
        </Grid>
    </Window>
    

    Window1.xaml.cs

    using System;
    using System.Threading;
    using System.Windows;
    using System.Windows.Media.Imaging;
    using System.Windows.Threading;
    
    namespace BitmapFrameDemo {
        public partial class Window1 : Window {
            private Thread       thread     = null;
            private Dispatcher   dispatcher = null;
    
            private void ThreadMain() {
                PngBitmapDecoder decoder    = new PngBitmapDecoder(
                    new Uri("http://stackoverflow.com/content/img/so/logo.png"),
                    BitmapCreateOptions.None,
                    BitmapCacheOption.Default);
                BitmapFrame      frame      = decoder.Frames[0];
                BitmapFrame      frozen     = (BitmapFrame) frame.GetAsFrozen();
                dispatcher.Invoke(
                    new Action(() => { image.Source = frozen; }),
                    new object[] { });
            }
    
            public Window1() {
                InitializeComponent();
    
                dispatcher = Dispatcher.CurrentDispatcher;
                thread = new Thread(new ThreadStart(this.ThreadMain));
                thread.Start();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 171k
  • Answers 171k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If Windows Service isn't an option, you can simply create… May 12, 2026 at 2:22 pm
  • Editorial Team
    Editorial Team added an answer It happens because of the document.write call. Here's some info… May 12, 2026 at 2:22 pm
  • Editorial Team
    Editorial Team added an answer In terms of runtime performance, it should make no difference… May 12, 2026 at 2:22 pm

Related Questions

I have posted several questions related to this problem I am having and I
I have some UI in VB 2005 that looks great in XP Style, but
I have some ASP.NET web services which all share a common helper class they
I have some code for starting a thread on the .NET CF 2.0: ThreadStart

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.