When i wrote creating an STA object from an MTA thread I meant - I have a .net thread that is an MTA thread and it creates an object that is marked in the registry as apartment.
The question is - on the MSDN it is written that calling from an STA thread to an objet in STA apartment is very fast. Does they mean - from the thread that created that COM object only? otherwise there is a very heavy penalty?
I think so, yes.
just because the marshaler?
I think there are at least two effects which contribute to the overhead here:
1) Since two threads communicate with each other, parameters and return values need to be transported between the two stacks.
2) Method calls to STA threads are performed by posting messages to the target STA's message queue from where the target thread reads and executes them. So if you have some thread A in STA-A, and some other thread B in STA-B, method calls from A to B are performed via B's message queue rather than by a direct call. Posting to and reading from a message queue is slower than low-level RPC communication (which is used for other apartment types).
If so I would imagine that to call from an MTA thread to a STA object would be even slower - why is it much faster?
I'd love to know the answer, too. My expectation would be that the MTA thread also posts requests to the STA's message queue, so performance should be in the same ballpark. But it isn't, so my expectations must be wrong or at least incomplete, which means that all my other logic might be faulty as well.
That said, I've described everything from a COM point of view. Managed code might have its own rules and subtleties which change the picture.
We just tring to figure out the best way to use STA objects from managed application.
Apparently, both of us are running similar experiments these days. I hope we'll learn more in the upcoming weeks, so maybe we could revisit the subject later.
Claus
=================================== This list is hosted by DevelopMentor� http://www.develop.com Some .NET courses you may be interested in:
NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls
View archives and manage your subscription(s) at http://discuss.develop.com
