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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:36:38+00:00 2026-05-19T01:36:38+00:00

In my program there is a BackgroundWorker class that preloads the images to BitmapImage

  • 0

In my program there is a BackgroundWorker class that preloads the images to BitmapImage object. I need to pass that preloaded image to the main application(WPF), where it will be copied to another BitmapImage object. This seems to be working, however, when i try

imgViewer.Source = imgNext;  //imgNext is a main app copy of the preloaded image

an error occurs meaning that that object(imgNext) is owned by another thread and it cannot be used.

Any ideas how to get rid of it and get the code working?

Thanks everybody for answering!

In fact, I managed to solve this problem by creating a static BitmapImage inside App class.
Before using it, I do

 App.iNext = null;

Then I load the actual image and freeze it, so this static property can be accessed from everywhere. When the cycle repeats many times, assigning null prevents ‘object is frozen’ errors.

And of course, there was a lot of work with managing single BGW instance, queuing tasks etc.

(Currently I’m using ImagesContainer class defined also in my program that has two BitmapImage properties. I use it to receive preloaded images from backgroundworker. )

imgNext is a public variable defined in MainWindow. (main thread)

 void bwImgLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            backgrLoadNextPrevList list =  e.Argument as backgrLoadNextPrevList;
            ImagesContainer result = new ImagesContainer();
            if (list.HasNextPath) result.imgPrev = PrepareImage(list.NextPath);
            if (list.HasPrevPath) result.imgNext = PrepareImage(list.PrevPath);
            e.Result = result;
        }
void bwImgLoader_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            ImagesContainer result  = e.Result as ImagesContainer;
            if (result.imgNext != null)
            {
                setNextDelegate s = new setNextDelegate(setNext);
                object[] t = { result.imgNext };
                imgNext.Dispatcher.Invoke(s, t);
            }
            // do not take into account this line, just ignore it. 
            //if (result.imgPrev != null) imgPrev = result.imgPrev;
        }
        public void setNext(BitmapImage b)
        {
            imgNext = b;
        }
        public delegate void setNextDelegate(BitmapImage b);

Freezing the bitmapimage helps only on the first background load(see the comment under the answer below). When I call BackgroundWorker second time, an errors occures that the object is frozen and cannot be modified. Is there a way to un-freeze it?

Or, is there any way to copy data from one thread to another without copying an attribution to thread?



UPDATED

Thanks everybody for answering!

In fact, I managed to solve this problem by creating a static BitmapImage inside App class.
Before using it, I do

 App.iNext = null;

Then I load the actual image and freeze it, so this static property can be accessed from everywhere. When the cycle repeats many times, assigning null prevents errors.

And of course, there was a lot of work with managing single BGW instance, queuing tasks etc.

But these efforts were worth the result – I got +125% in performance!!! Thank everyone!

  • 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-19T01:36:39+00:00Added an answer on May 19, 2026 at 1:36 am

    BitmapImage is Freezable so you can Freeze() it after loading it. This will permit access from any thread.

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

Sidebar

Related Questions

Is there a program that will print a nicely formatted tree from XML data?
Is there any way to launch a program with a shortcut, that sets the
There's this program, pdftotext, that can convert a pdf file to a text file.
I have a VBA application that creates an instance of a COM object and
In my program there is a complex calculation that requires the user to evaluate
In my program there are two datetimepickers. I need to get the days in
I have been working on a childish little program: there are a bunch of
Is there a program or API I can code against to extract individual files
I've had a tough time setting up my replication server. Is there any program
Is there a simple and lightweight program to search over a text file and

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.