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 8141201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:25:35+00:00 2026-06-06T12:25:35+00:00

I declared a field: WriteableBitmap colorBitmap; Then I created a simple thread which does

  • 0

I declared a field:

WriteableBitmap colorBitmap;

Then I created a simple thread which does something:

private void doSomething()
{
    // ... bla bla bla
    colorBitmap = new WriteableBitmap(/* parameters */);
    myImage.Source = colorBitmap; // error here:S
}

In Windows_Loaded event I declared and started a new thread:

private void window_Loaded(object sender, RoutedEventArgs e)
{
    Thread th = new Thread(new ThreadStart(doSomething));
    th.Start();
}

The problem is that I couldn’t change myImage’s source. I’ve got an error like:

InvalidOperationException was unhandled
The calling thread cannot access this object because a different thread owns it.

I tried to use Dispatcher.Invoke, but it didn’t help…

Application.Current.Dispatcher.Invoke((Action)delegate
{
    myImage.Source = colorBitmap;
});

I was searching for some answers, but never found the case exactly as mine. Could any1 help me to understand how to solve problems like this (I’ve had the same problem recently, but I couldn’t call the method, because other thread owned it).

  • 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-06-06T12:25:36+00:00Added an answer on June 6, 2026 at 12:25 pm

    There are two problems with your code:

    1. You can’t access the WriteableBitmap from another thread that is different than the one who created it. If you want to do that, you need to freeze your bitmap by calling WriteableBitmap.Freeze() first

    2. You can’t access myImage.Source in a thread that is not the dispatcher thread.

    This should fix both of these two problems:

    private void doSomething()
    {
        // ... bla bla bla
        colorBitmap = new WriteableBitmap(/* parameters */);
        colorBitmap.Freeze();
        Application.Current.Dispatcher.Invoke((Action)delegate
        {
            myImage.Source = colorBitmap;
        });
    }
    

    EDIT
    Note that this approach allows you to create and update your bitmap wherever you want in your thread. Once the bitmap is frozen, it can no longer be modified in which case you should just trash it and create a new one.

    On a side note, if you wish not to block your thread updating myImage.Source use BeginInvoke instead of Invoke

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class A, which have a field val declared as private. I
If I have a table with a field which is declared as accepting varchar(100)
I want to get the name of the field with which it was declared
I have declared a private field and a public property for a given class.
The following program is accessing and modifying a private field named privateKey declared within
I recently ran across a class that had the following field declared: private final
I have a varchar(1000) column declared as field that contains all numbers, as shown
I am trying to search on a field declared as 'text' using the wildcard
I'm looking to access the generic type of a declared field during runtime. I
I have a table in my database with one field declared as _id integer

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.