Monday, April 22, 2013

Threading Model : STA vs. MTA

http://msdn.microsoft.com/en-us/library/windows/desktop/ms693779(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms695279(v=vs.85).aspx

To instruct object to use which thread model.
Of course, use STA will be safe but poor performance. Use MTA is vice versa.

It is easier to support apartment threading in single-threaded apartments because COM provides synchronization on a per-call basis. Supporting free-threading is more difficult because the object must implement synchronization; however, response to clients may be better because synchronization can be implemented for smaller sections of code.

NTA
When an object that is configured to run in the neutral threaded apartment (NTA) is called by a thread that is in either an STA or the MTA, that thread transfers to the NTA. If this thread subsequently calls CoInitializeEx, the call fails and returns RPC_E_CHANGED_MODE. 

No comments:

Related Posts Plugin for WordPress, Blogger...