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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:43:08+00:00 2026-05-20T00:43:08+00:00

I haven’t used OLE/COM for quite some time as a developer, but I currently

  • 0

I haven’t used OLE/COM for quite some time as a developer, but I currently have a need to use some 3rd party OCX code libraries from a C# program.

The C# program uses threading (it’s a TCP socket server). The OCXs are marked as Apartment threading model. From my reading, I concluded that if I was careful to create one instance of each OCX per thread, and only to use that instance from the thread that created it, I should be OK.

I did also do:-

myThread.SetApartmentState(ApartmentState.STA);

before starting each thread.

Should this be enough to ensure safe use of the OCXs?

The symptom I’m seeing is that threads can all create OCXs but on an apparently random basis, the calls to prepare and initialize the OCXs fail. They don’t seem to return any useful information as to why.

Can anyone explain what I’m seeing, or give me a guide to using these OCXs safely from threaded code?

Alternatively, should I just give up and create a single instance of each and all OCXs in one thread, and send all calls to them via a threadsafe queue or similar?

  • 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-20T00:43:08+00:00Added an answer on May 20, 2026 at 12:43 am

    Marking a component as Apartment threaded is just an assertion from the component developer. There are plenty of component developers around who don’t understand threading, and even those who do understand threading sometimes get it wrong, so it’s an act of faith to trust this assertion.

    Personally I’m very wary of using 3rd party components in a multithreaded environment for that reason. Except those that I know have had very wide exposure in multithreaded applications, and/or for which I know I can get adequate support.

    If you don’t have access to support from the component developer, or source code for the component, and you absolutely need to use it, then the option of creating a single instance may be a good pragmatic solution.

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

Sidebar

Related Questions

i have a input tag which is non editable, but some times i need
Haven't done ASP.NET development since VS 2003, so I'd like to save some time
I haven't used a png hack for IE6 for ages. Last time I used
Haven't fired up reflector to look at the difference but would one expect to
Haven't seen many Geneva related questions yet, I have posted this question in the
I haven't used C++ since college. Even though I've wanted to I haven't needed
I haven't completely understood, how to use sigprocmask() . Particularly, how the set and
I haven't seen any questions relating to GNU autoconf/automake builds, but I'm hoping at
I haven't done a lot of .NET programming, but I've examined a few of
I have just tried to save a simple *.rtf file with some websites 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.