Willy Denoyette [MVP]
7/2/2007 4:13:00 PM
<zabutimaxim@gmail.com> wrote in message
news:1183380558.740233.113400@q75g2000hsh.googlegroups.com...
> Hi,
>
> I have following strange problem. I run remote object using .NET
> remoting.
> This remoting object creates some COM object (STA) and executes some
> methods.
> The strange behavior is that if I print GetCurrentThreadId inside
> remote object I see
> that each call run in different thread id, but print from COM object
> gives me same
> thread id all the time. Under the stress it hase same exactly
> behavior.
> Can anyone explin me why it happens? Is there any article about this
> in MSDN?
>
> Thanks,
> Maxim.
>
"Apartment" threaded objects cannot run on an MTA thread, they *must* run on
a STA thread, this is automatically taken care of by COM. That means that
your objects are getting created on a "COM" thread that is initialized to
enter an STA and your calls will get COM marshaled by a proxy/stub pair from
the MTA thread to the COM STA thread.
In order to prevent the marshaling overhead (and other marshaling related
issues), you should try to re-implement your COM objects as free threaded.
Willy.