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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:51:35+00:00 2026-05-29T10:51:35+00:00

I have a slow method that I’d like to run in a separate thread.

  • 0

I have a slow method that I’d like to run in a separate thread.
This method uses a call on a COM object created in the main thread of the app.

Lets assume the code that is slow is this:

var bwImg = image.GetBitonalImage(); // <- slow image is a COM created in main thread
viewer.Document = bwImg; // <-- ATL control accepting the B/W COM image 

If that matters, I am doing this in a WPF application and ‘viewer’ is in a WinFormsHost.

I assumed that doing this would make this asynchronous and not block the running of the application:

var t = new Thread((ThreadStart)(() =>
{
    var bwImg = image.GetBitonalImage(); // <- this is in separate thread
    Dispatcher.Invoke((Action)(() =>
    {
        viewer.Document = bwImg; // <- this again on the main
    }));
}));
t.Start();

It is ok for me that the images gets shown at some later time, and I do not care how much later.

But it happens that the application is blocked in the same way.
I did profiling and indeed most time is spent in GetBitonalImage, and almost none in ‘viewer.Document = bwImg’.

Removing the code altogether makes the app responsive, so it’s not other code fault.

There is other code later after this that uses the same image COM object (not the B/W result but the original).

Is this the correct way to do this? Can the problem be because of the COM object method call?

  • 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-29T10:51:36+00:00Added an answer on May 29, 2026 at 10:51 am

    Is your COM object threadsafe? If it’s not, then it might be initialized in STA (single-threaded apartment) mode, which would use the STA thread to do its work. So even though you spun up a new thread, it would switch back to the STA thread, blocking your UI events. If you have control over the source for the COM library you could change those settings, as long as the code is actually threadsafe.

    Edit: Found this link in the related posts section, it might be applicable to you. UI thread is blocking a background thread calling a COM object.

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

Sidebar

Related Questions

I have a method that gets rows from my database. It looks like this:
I have a method that I would like to call when a 2 finger
I have a drawRect method that is rather slow (100-200ms). To save time, I
I have a loop that looks like this def slow_loop(array) array.each_with_index do |item, i|
I have the following query method that has slow performance: @Override public Map<String, Long>
I have a hidden div which I reveal with the jquery fadein() method: $(#panel).fadeIn(slow);
I have some slow internet task to save and load file, I'd like to
I have a slow connection that I need to send a PNG image over
I have a Website that is really slow and feels really bad when using
I have read that gwt-ext is slow and it seems too bulky. How does

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.