This is one major difference between VB6 and .NET. In VB6 all of the
objects you create are STA COM objects. This is what caused the events to
be marshaled back to the primary thread. .NET objects have no concept of
thread affinitiy [1]. The best way to view a .NET object is that it is a
MTA object that aggregates the free threaded marshaller, (or that it lives
in the thread nuetral apartment).
You will have to manually Marshal these events back to the foreground
thread.
[1] Technically ContextBound objects do have a concept of thread affinity
but that's not relevant in this scenario.

Signature
Jared Parsons [MSFT]
jaredpar@online.microsoft.com
http://blogs.msdn.com/jaredpar
"This posting is provided "AS IS" with no warranties, and confers no rights"
> My .NET application handles events from an out-of-proc COM server. These
> events do not execute on the app's primary thread, however. Is this a
> consequence of COM Interop or can this be controlled? (The .NET app is
> configured to run in a STA.) In a VB6 program, the events are executed on
> the primary thread. Thanks for the help.
Thanks for the explanation. Switching to the primary thread to handle the
event solved the original problem, which was slow execution on in-proc,
apartment-threaded COM server methods. (Roughly 80 times faster on the
primary thread!)
Thinking that cross-apartment marshaling was responsible, I changed the
in-proc server to the free-threaded model, but the timings didn't improve.
Was cross-apartment marshaling a bad theory or is .NET/COM Interop somehow
affecting this? Thanks again for the help.
> This is one major difference between VB6 and .NET. In VB6 all of the
> objects you create are STA COM objects. This is what caused the events to
[quoted text clipped - 15 lines]
>> on
>> the primary thread. Thanks for the help.
"Peter Huang" [MSFT] - 31 Aug 2005 03:47 GMT
Hi George,
I think cross-apartment marshaling was to provide the ability to do COM
call when they lives in the different apartment.
So cross-apartment do will have some performance hit, but that is necessary
when we have to do cross-apartment marshaling, because the COM call between
apartments is common. We can not make sure all the COM call occur on the
same thread, that will limit the COM's ability.
Also the .NET Interop will also need some more effort to do the COM/.NET
type converting and parameter passing....
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Willy Denoyette [MVP] - 01 Sep 2005 17:04 GMT
I'm missing something here, you are talking about an out-proc COM server, in
this scenario there is no cross-apartment marshaling involved, all there is
is cross-process marshaling over DCOM which is allways much slower than
in-proc marshaling between incompatible apartments.
Question is what out-proc server are you talking about? Is this a VB6
ActiveX server?
Willy.
> Thanks for the explanation. Switching to the primary thread to handle the
> event solved the original problem, which was slow execution on in-proc,
[quoted text clipped - 26 lines]
>>> on
>>> the primary thread. Thanks for the help.
George - 05 Sep 2005 22:57 GMT
In handling a COM event from the out-of-proc server, the app calls a method
on an in-proc server. This method executes more slowly when called from the
event handler than it does if called from the app's primary thread. I
suspected marshaling was responsible since the event handler thread
(affiliated with an MTA) was using a COM object created in a STA. Creating
the in-proc COM object in an MTA however, did not improve performance.
> I'm missing something here, you are talking about an out-proc COM server,
> in this scenario there is no cross-apartment marshaling involved, all
[quoted text clipped - 35 lines]
>>>> on
>>>> the primary thread. Thanks for the help.
Yan-Hong Huang[MSFT] - 05 Sep 2005 04:09 GMT
Hello George,
I am reviewing the issue thread. Do you still have more concerns on it? If
there is any question, please feel free to post here and we will follow up.
Thanks very much.
Best regards,
Yanhong Huang
Microsoft Community Support
Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn
This posting is provided "AS IS" with no warranties, and confers no rights.
George - 05 Sep 2005 23:03 GMT
Hi Yanhong Huang,
Thanks for checking. We have opened a case with Microsoft Support on this
and are awaiting further information.
George
> Hello George,
>
[quoted text clipped - 15 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
"Peter Huang" [MSFT] - 06 Sep 2005 04:48 GMT
Hi
Thanks for your updated!
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Yan-Hong Huang[MSFT] - 06 Sep 2005 11:02 GMT
Hi George,
Thanks very much for your update. If it is convenient for you, could you
please update the community with the result after you communicate with
support team? Hopefully the community can benefit from it.
Thanks again for participating the community. Have a nice day.
Best regards,
Yanhong Huang
Microsoft Community Support
Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn
This posting is provided "AS IS" with no warranties, and confers no rights.