Specifying the threading model of a .NET class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Looking with OLE COM VIEWER at some .NET classes that were also registered
for COM, I found something surprising:

even though I can't find any differences in the attributes applied to
them,
some appear as Apartment and others as Both. Funny thing is all that
appear
as Apartment belong to the same assembly and all that appear as Both
belong
to another assembly, as if some setting at the level of the assembly was
involved.

Any ideas here?
 
Hi

I think this is concern about how the .NET class is implemented and how to
use.
Usually, a class can be loaded into MTA needs to implement more synchronize
code in multiple thread scenario.

Here are some links about MTAThreadAttribute and STAThreadAttribute
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemstathreadattributeclasstopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemMTAThreadAttributeClassTopic.asp


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Juan Dent said:
Hi,

Looking with OLE COM VIEWER at some .NET classes that were also registered
for COM, I found something surprising:

even though I can't find any differences in the attributes applied to
them,
some appear as Apartment and others as Both. Funny thing is all that
appear
as Apartment belong to the same assembly and all that appear as Both
belong
to another assembly, as if some setting at the level of the assembly
was
involved.

Any ideas here?

Not sure what .NET classes you are looking at but they all should be both.
Mind to tell us which class is 'apartment' ?

Willy.
 
Thank you again Peter!
Thanks Willy.

Actually, I am migrating a COM C++ system to .NET, and some of the classes
still exist in COM. And, as pointed out by Willy, I have come to realize that
all .NET classes indeed appear as BOTH. Only the older COM classes appear as
APARTMENT.

Sorry, didn't catch that. At least now I know that ALL classes created using
..NET MUST appear as BOTH, is that correct Willy?

--
Thanks in advance,

Juan Dent, M.Sc.
 
Juan Dent said:
Thank you again Peter!
Thanks Willy.

Actually, I am migrating a COM C++ system to .NET, and some of the classes
still exist in COM. And, as pointed out by Willy, I have come to realize
that
all .NET classes indeed appear as BOTH. Only the older COM classes appear
as
APARTMENT.

Sorry, didn't catch that. At least now I know that ALL classes created
using
.NET MUST appear as BOTH, is that correct Willy?

Yep, note that this is only important when you consume these 'COM' objects
from native COM clients, managed clienst don't know anything about
apartments.

Willy.
 
Back
Top