none
COM Apartment ? RRS feed

  • Question

  • If there is a STA thread call method from 2 different object COM, what is system do ?

    Create 1 apartment for every object COM or 2 apartment for 2 object COM ?

    And how about this thread belong to 1 apartment or 2 aparment ?

    tanx
    Wednesday, February 20, 2008 12:33 PM

All replies

  • No new apartments are created just because you call a method on a COM object. When you create the COM object the system will ensure it gets created in the appropriate context according to how it was registered.

    Wednesday, February 20, 2008 2:34 PM
    Moderator
  •  Mattias Sjögren wrote:

    When you create the COM object the system will ensure it gets created in the appropriate context according to how it was registered.



    Can u explain me what this meaning 'created in apropriate context according how it was registered ?
    Thursday, February 21, 2008 2:52 PM
  • If you for example have code running in the MTA and create an object of a coclass registered with ThreadingModel = Apartment, COM will have to create an STA for that object and return a proxy object to you.

     

    Here's a pretty good introduction to this whole topic: http://www.codeguru.com/cpp/com-tech/activex/apts/article.php/c5529

     

    Thursday, February 21, 2008 3:37 PM
    Moderator
  • No, it does'n t answer my question.

    My question is if we want to access method from 2 different COM from STA thread, does system will create 1 apartment for COM 1 and create other apartment for COM 2.

    If so the thread itself belong to which thread ?

    If not what system will do to that process , create single apartment for both COM ?
    Friday, February 22, 2008 12:46 AM
  •  IRW7 wrote:

    My question is if we want to access method from 2 different COM from STA thread, does system will create 1 apartment for COM 1 and create other apartment for COM 2.

     

    Again, that depends on how the COM objects are registered and on which thread they are created on. If they are both registered with ThreadingModel=Apartment and created on your STA thread, no additional apartments need to be created.

     

     

     IRW7 wrote:

    If so the thread itself belong to which thread ?

     

    I don't understand what you mean by this question, or if it even makes sense.

     

    Friday, February 22, 2008 2:58 PM
    Moderator
  • I 'm still new too this topic, and have read from MSDN's article. BTW the article itself really doeesn't make sense too me.

    Please correct my understanding about thread :

    STA thread

    1)   STA thread 1 that need method from any COM objects with apartment model will be place on new single apartment  ?

    2)   if there is other STA thread 2 (different from above) access same COM objects above, then system will create new single apartment again for thread 2  ?

    3)  if this STA thread 2 also call method from COM objects with multithread model then system will create 1 multithread apartment and place COM object to them. any STA thread call to these COMs willl done by proxy

    MTA thread


    1)   MTA thread 1 that need method from any COM objects with multithread model will be place on new multithread apartment  ?

    2)   if there is other MTA thread 2 (different from above) access same COM objects above, then system will place on current multithread apartment same with thread 1 , so both thread will share same COM without need to create other new COM ?

    3)  if MTA thread 2 also call method from COM objects with single model then system will create new single  apartment and place COM object to them. any MTA thread call to these COMs willl done by proxy

    TANX again
    Friday, February 22, 2008 11:45 PM
  •  IRW7 wrote:
    I 'm still new too this topic, and have read from MSDN's article. BTW the article itself really doeesn't make sense too me.

    Please correct my understanding about thread :

    STA thread

    1)   STA thread 1 that need method from any COM objects with apartment model will be place on new single apartment  ?

    2)   if there is other STA thread 2 (different from above) access same COM objects above, then system will create new single apartment again for thread 2  ?

    3)  if this STA thread 2 also call method from COM objects with multithread model then system will create 1 multithread apartment and place COM object to them. any STA thread call to these COMs willl done by proxy

    MTA thread


    1)   MTA thread 1 that need method from any COM objects with multithread model will be place on new multithread apartment  ?

    2)   if there is other MTA thread 2 (different from above) access same COM objects above, then system will place on current multithread apartment same with thread 1 , so both thread will share same COM without need to create other new COM ?

    3)  if MTA thread 2 also call method from COM objects with single model then system will create new single  apartment and place COM object to them. any MTA thread call to these COMs willl done by proxy

    TANX again


    Can some1 who expert and know about COM apartment in a process , please give comment wether is it true or false and give me explanation if exist ?

    TANX
    Wednesday, March 5, 2008 10:29 AM