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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:18:43+00:00 2026-05-13T09:18:43+00:00

I’m using com interop to talk to some physical piece of hardware. When I

  • 0

I’m using com interop to talk to some physical piece of hardware.

When I need the current reading from the hardware I have a nice elaborate piece of threading code that keeps it off my UI thread so that I don’t lock up the UI while I query the hardware since sometimes it can take as much as 1-2 minutes (although usually more like 1-5 seconds).

So once I step into the com object it bounces back to the main UI thread and the UI becomes busy during the duration of the reading.

The main app is a .net WPF app, so it STA by default.
The COM object is created on the main thread, but it’s created my a singleton factory, so all of these objects are created by the same few lines of UI.

I’d love to show some code, but it’s not like the stuff is in just a few lines of code.

What kind of work arounds are there for this behavior?
I’d also love to be able to read from multiple com object simultaneously.

If were to create background threads to spin up these com objects inside my object facotry. How do I keep them alive to handle the work that gets marshaled back to them?

  • 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-13T09:18:43+00:00Added an answer on May 13, 2026 at 9:18 am

    I have it working.

    Previously my constructor worked like:

    internal class Device
    {
        private ComDeviceLibrary.UberDevice myDevice;
    
        internal Device(DeviceInitObject myInitOptions)
        {
            myDevice = new ComDeviceLibrary.UberDevice();
        }
    }
    

    Now if I do this:

    internal class Device
    {
        private ComDeviceLibrary.UberDevice myDevice;
    
        internal Device(DeviceInitObject myInitOptions)
        {
    
            AutoResetEvent createHandle = new AutoResetEvent(false);
            Thread creationThread = new Thread(CreateDevice);
            creationThread.IsBackground = false;
            creationThread.SetApartmentState(ApartmentState.MTA);
            creationThread.Start(createHandle);
            createHandle.WaitOne();
        }
    
        private void CreateDevice(object objWaitHandle)
        {
    
            myDevice = new ComDeviceLibrary.UberDevice();
            ((AutoResetEvent)objWaitHandle).Set();
        }
    }
    

    It works!

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.