Tuesday 15 September 2015

windows - Why would I use "Both" COM threading model instead of "Free"? -


According to

If I register my COM object with "both" or "free" threading model then the object is completely Thread-safe from Especially all uses of the global shared variable should be synchronized and all usage of member variables should also be synchronized. It is very hard.

Now I understand that using the "free" threading model is beneficial for being able to register my object and it may be worth the cost of making it completely thread-safe. But why would I want to all equally and would like to use my object instead of "both" threading model? What will be the benefit? How do I choose between "both" and "free"?

both the threading model

of the threading model The main reason for marking your constituents as a support is to improve both "performance" when the component is called single-threaded apartment (STA).

If you mark your component as an MTA and your component is made from within STA then your component will be made in a separate MTA apartment and, however, if the threading model of your component If marked as "both", then it will be built inside the apartment of the STA object and will be delivered directly.

So if you think that your component can be said within STA, all VB6 COM objects are STA) you may want to mark the threading model as "both".

A good KB article.

Free threading model

If your component uses other components marked as "Free" then you can use the "Free" thread model You may want to use if your component was marked as "both" then there may be excessive switching of apartments between the "both" components running in STA and MTA. As a general rule, try to make components close to the collar (i.e. the same apartment) while working properly in all situations.

Another condition that is explicitly blocking your component as "free" (such as thread. Sleep), if the component is marked as "both" and immediately in STA, then component STA The message will block the pump.

Other things and scenarios

If you are planning to use components in IIS, then there are other things to consider for IIS , "Both" recommended settings are primarily used by the apartments for threaded components, the use of exec + to COM + ObjectContext, and the fact that "free" threaded components use system security context (if you enter the user's security context Needing With) to avoid locking issues. For more information about IIS threading ideas, see.

COM + Support has other things to consider and how your components behave if you are run in COM + and interface points are passed and stored.

An excellent article is. Contains COM + Focus but it also discusses COM for your question, read the section titled "Threading Model Recommendations", Microsoft has removed the original article, so I'm linking to a copy.


No comments:

Post a Comment