I have a VB COM client and an in-process COM object (VC++) both in the same STA. However, I need to add some asynchronous functionality to the COM object, creating worker threads to do concurrent processing. I am thinking that the COM object now has to be created in an MTA so that the asynchronous calls from the worker threads to the COM object are not serialised by the STA message queue. Is this correct?
Also, if I now have an STA client making lots of calls to a COM object in the MTA, I am concerned that the marshalling overhead may negate any performance improvements I make by introducing multi-threading in my COM object. Is this likely if the inter-apartment calls are in the same process - is the marshalling overhead between apartments in the same process the same as marshalling between different processes?
I am a bit stuck here, as I cannot rewrite the VB client so this has to stay an STA, and my COM object needs to be in an MTA to acheive multi-threading (the threads make calls to the COM object).
Marshalling within the same process uses LRPC, a light weight version of RPC that is designed for better performance than RPC. So it would definitely be much better in performance than an out-of-process call.
If you are creating worker threads inside the COM component and the client doesn't need to know about it, you can still use STA.
«_Superman_» I love work. It gives me something to do between weekends.
My COM object creates worker threads that make asynchronous calls to another interface of the same COM object - I have assumed that this means I need to have the COM object in an MTA (and the worker threads)? If the COM object was in an STA, then the worker threads would have to join separate STAs since an STA can only have one thread. So, calls from the worker thread STAs to the COM obejct STA would be serialised by the COM STA message queue, negating my attempt to have asynchronous processing. Have I got this right or am I in a muddle?
My worker threads need to have access to the COM object and I have assumed that they cannot access the internal COM object and can only access it via an interface. This interface pointer will be passed to the thread functions. I need the worker threads to perform operations on the COM object in parallel.
If there was another way I could do this, then that would be great?