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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:29:22+00:00 2026-06-11T22:29:22+00:00

My application runs CPU-heavy algorythms to edit an Image placed at a WPF window.

  • 0

My application runs CPU-heavy algorythms to edit an Image placed at a WPF window. I need the edition to be done in a background thread. However trying to edit the BackBuffer of WritableBitmap in non UI thread throws InvalidOperationException.

    private WriteableBitmap writeableBitmap;

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        // Create WritableBitmap in UI thread.
        this.writeableBitmap = new WriteableBitmap(10, 10, 96, 96, PixelFormats.Bgr24, null);
        this.image1.Source = this.writeableBitmap;

        // Run code in non UI thread.
        new Thread(
            () =>
            {
                // 'Edit' bitmap in non UI thread.
                this.writeableBitmap.Lock(); // Exception: The calling thread cannot access this object because a different thread owns it.

                // ... At this place the CPU is highly loaded, we edit this.writeableBitmap.BackBuffer.

                this.writeableBitmap.Unlock();
            }).Start();
    }

I have read dozens of manuals, all of them tells me to do the BackBuffer edition in UI thread (i.e MSDN).

How to edit the WritableBitmap.BackBuffer in a non UI thread without any useless buffer copying/cloning?

  • 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-11T22:29:23+00:00Added an answer on June 11, 2026 at 10:29 pm

    MSDN suggests writing to the backbuffer in a background thread. Only certain pre- and post update operations need to be carried out on the UI thread. So while the background thread is doing the actual updating, the UI thread is free to do other things:

            //Put this code in a method that is called from the background thread
            long pBackBuffer = 0, backBufferStride = 0;
            Application.Current.Dispatcher.Invoke(() =>
            {//lock bitmap in ui thread
                _bitmap.Lock();
                pBackBuffer = (long)_bitmap.BackBuffer;//Make pointer available to background thread
                backBufferStride = Bitmap.BackBufferStride;
            });
            //Back to the worker thread
            unsafe
            {
                //Carry out updates to the backbuffer here
                foreach (var update in updates)
                {
                    long bufferWithOffset = pBackBuffer + GetBufferOffset(update.X, update.Y, backBufferStride);
                    *((int*)bufferWithOffset) = update.Color;
                }
            }
            Application.Current.Dispatcher.Invoke(() =>
            {//UI thread does post update operations
                _bitmap.AddDirtyRect(new System.Windows.Int32Rect(0, 0, width, height));
                _bitmap.Unlock();
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The application has a CPU intensive long process that currently runs on one server
Codeplex offers a feature to display / monitor application runs. There is a sample
I created an application in MonoDevelop, the application runs correctly (as far as I
I have a ASP.NET MVC application using NHibernate and the application runs fine when
I have to copy a psTool utility to System32 folder when my application runs.
I recently upgraded from Grails 1.3.7 to Grails 2.0.1. The application runs normal, but
My application (DotNET) runs as a plug-in inside a C++ standalone app that exposes
The application which runs smoothly on 4.0.1 when was tried on run on 4.2.1
I have a application that runs very well on JBoss using JSF 2. I
Given a Cocoa application which runs on Mac OS X 10.7 and later: What

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.