[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

.NET remoting and COM strange behavior

zabutimaxim

7/2/2007 12:49:00 PM

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.

2 Answers

Christian Fröschlin

7/2/2007 1:20:00 PM

0

zabutimaxim@gmail.com wrote:

> 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.

By definition of STA, all calls to the COM object are executed
in the thread which *created* the object. Create an MTA object
if this is not what you want.

Willy Denoyette [MVP]

7/2/2007 4:13:00 PM

0

<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.