Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
COM+ Threading Models
Collapse the table of content
Expand the table of content

COM+ Threading Models

COM+ threading models are designed around an object collection called an apartment. An apartment is a collection of contexts contained in a process, as shown in the following illustration.

ms686448.6b86fe3b-262a-483a-a418-67d60f9a5d68(en-us,VS.85).png

Calls within an apartment are direct, while calls across apartments (out-of-process) are indirect and require proxy and stub code. Apartments allow for objects with different synchronization and reentrancy properties and have two categories: single-threaded and multithreaded. Objects in a single-threaded apartment (STA) execute on the particular thread in which they were created. STAs allow only one method to execute at a time. They are designed for user interfaces and rely on the Microsoft Windows message queue to process incoming calls.

Objects in a multithreaded apartment (MTA) execute on any thread and allow any number of methods to occur simultaneously. MTAs support reentrance implicitly.

COM+ classes are marked with a ThreadingModel property that allows COM+ to create the object in the proper apartment. To determine which apartment an object is created in, CoCreateInstance uses the ThreadingModel property.

Threads must call CoInitializeEx before they can use COM+. This creates them inside the correct apartment and context. The main thread apartment is determined to be the first STA called by CoInitializeEx. This is usually associated with the main thread of a process. CoInitializeEx indicates the type of apartment required by the thread by setting the following flags:

  • COINIT_MULTITHREADED—Locates the thread in the single multithreaded apartment.
  • COINIT_APARTMENTTHREADED—Places the thread into a new STA.

The following topics in this section provide more information about using threading models and apartments in COM+:

Related topics

Processes, Threads, and Apartments
ThreadingModel

 

 

Community Additions

ADD
Show:
© 2015 Microsoft