That was exactly my problem. Here is how to resolve it...
An exported managed server (COM Object) with a type library registered by
the Assembly Registration tool (Regasm.exe) has a ThreadingModel registry
entry set to Both. This value indicates that the server can be activated in a
single-threaded apartment (STA) or a multithreaded apartment (MTA). The
server object is created in the same apartment as its caller.
Because the client and server are in the same apartment, the interop
marshaling service automatically handles all data marshaling.
Thus, you can use the CoInitializeEx(NULL, COINIT_MULTITHREADED) from your
native thread to ensure that the objects are created in MTA. (Please make
sure that CoInitializeEx() is called at the earliest point in the execution
of the thread, with a matching CoUninitialize at the end.)
[quoted text, click to view] "Mattias Sjögren" wrote:
>
> >I have written an object in C# and exposed it as a COM object. This object
> >is used in a native application and that application creates one or more
> >threads that creates and uses its own copy of my C# COM object.
> >
> >My C# COM object has reduced my performance of my native application because
> >all objects are create in a single threaded apartment. A call to
> >Thread.GetApartmentState() inside my C# COM object returns ApartmentState.STA.
>
>
> How does your client initialize COM on those threads? Managed classes
> registered for COM interop are set to ThreadingModel = Both, so they
> should happily enter the MTA.
>
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP] mattias @ mvps.org
>
http://www.msjogren.net/dotnet/ |
http://www.dotnetinterop.com > Please reply only to the newsgroup.