COM Apartment
-
Hi Guys, Reading about COM Threading since two days.. But still i Couldnt understand Exactly " What is an Apartment ". Kindly can any one explain in simple terms or show some source to understand more. Thanks, TV Krishna Rayalu
-
Hi Guys, Reading about COM Threading since two days.. But still i Couldnt understand Exactly " What is an Apartment ". Kindly can any one explain in simple terms or show some source to understand more. Thanks, TV Krishna Rayalu
-
A good description can be found on this MSDN page[^]. Basically it is whether the COM object can support multi-threading or not: crazy Microsoft terminology again.
Use the best guess
Thanks Richard. That link is informative. i could able to understand STA and MTA, i got more discription on what STA and MTA do then what exactly Apartment is. Can you please define it in simple words. Thanks & Regards, TV Krishna Rayalu
-
Thanks Richard. That link is informative. i could able to understand STA and MTA, i got more discription on what STA and MTA do then what exactly Apartment is. Can you please define it in simple words. Thanks & Regards, TV Krishna Rayalu
KRISHNARAYALU wrote:
Can you please define it in simple words.
Define what? The link I gave you uses fairly simple words, and explains exactly what the difference is. If you do not understand the difference between single-threaded and multi-threaded code, then you should avoid using COM.
Use the best guess
-
KRISHNARAYALU wrote:
Can you please define it in simple words.
Define what? The link I gave you uses fairly simple words, and explains exactly what the difference is. If you do not understand the difference between single-threaded and multi-threaded code, then you should avoid using COM.
Use the best guess
Richard, I may missed something vital in that article or Some basic in that concept. I will re read the article. Thanks for Support. Thanks & Regards, TV Krishna Rayalu
-
Hi Guys, Reading about COM Threading since two days.. But still i Couldnt understand Exactly " What is an Apartment ". Kindly can any one explain in simple terms or show some source to understand more. Thanks, TV Krishna Rayalu
First of all an apartment is an abstract concept, means, there is no physical thing behind. When a thread starts it decides in which apartment it wants to "live". It does so by calling
CoInitialize
orCoInitializeEx
. An apartment is a kind of a convention how to handle things. A thread that initializes a single-threaded apartment states, that it does not allow any other threads to enter the same apartment. COM knows then, that all objects living in this apartment can be accessed only from this same thread and makes sure that these objects are used only from within this thread. A thread that initializes a multi-threaded apartment allows other threads. COM knows then, that multiple threads might access the objects in this apartment and relies on these objects to handle thread synchronization by themselfs. So how do other threads enter the same apartment? Simply also viaCoInitializeEx
. By requesting a multi-threaded apartment they will automatically resist in the same apartment as the other MTA threads since there can only be one MTA. So in the end each thread that initializes a STA creates its own apartment, while threads initializing MTA enter the one and only MTA. And the same is of course valid for all COM objects created from this thread. -
Hi Guys, Reading about COM Threading since two days.. But still i Couldnt understand Exactly " What is an Apartment ". Kindly can any one explain in simple terms or show some source to understand more. Thanks, TV Krishna Rayalu