I have not used OLE / COM for some time as a developer, but currently I need to use some third-party OCX code libraries from a C # program.
The C # program uses threads (it is a TCP socket server). OCX marked as a model of streaming data. From my reading, I came to the conclusion that if I tried to create one instance of each OCX for the stream, and only to use this instance from the stream that created it, I should be fine.
I also did: -
myThread.SetApartmentState(ApartmentState.STA);
before the start of each thread.
Should this be enough to ensure safe use of OCX?
The symptom I see is that threads can create OCX, but apparently randomly, calls to prepare and initialize OCX fail. They do not seem to return any useful information on why.
Can someone explain what I see, or give me a guide on how to safely use these OCX from multi-threaded code?
Alternatively, should I just give up and create one instance of each and all OCX in one thread and send all calls to them over a streaming network or similar?
source share