4
votes

I have been reading a lot about COM apartments and .NET interop, but I have not found an answer to this question yet. It leads me to believe that I might be asking the wrong question.

I know that the .NET threads, like native threads can be both MTA or STA and I find documentation on this, bit I see very little about how the objects and their CCWs associate with these apartments.

My guess is that the threading model of the CCWs is 'Both' and that the CCW associate with whichever apartment the creating thread is part of.

Which apartment is a CCW associated with, and am I able to control this behavior?

1

1 Answers

4
votes

.NET-implemented COM objects can in general live in any kind of COM apartment. By default the .NET methods/tools for registering .NET assemblies as COM servers will register the coclasses with threading model = Both.

If you want to expose a .NET class as a COM coclass with a different threading model (e.g. to force into an STA) then you'll need to provide a customised registration function.