'Object apartment vs Thread apartment
I read about apartment model, but it is still confusing me when I'm trying to understand the following: whose apartment dictates the apartment model? Is it the thread's apartment or the apartment of the created object?
Consider the following scenario:
I've created C++ ATL COM dll that has only one interface which is
ISimpleCom, and I have a class the implements that interface which has only one methodtest();This class publicly inherit fromCComObjectRootEx<CComSingleThreadModel>which sets STA apartment.Reference this DLL in C# WinForms project, and create the
SimpleComobject on a MTA thread (not the UI thread). The question is: Lets say UI thread calltest()on this object, will it be marshaled to the thread created the object or it will be executed on the UI thread ?- If it follows the object COM apartment this call should be marshaled to the thread who created the object because it is an STA object.
- If it follows creating thread apartment which is MTA, it should be executed on the UI thread.
Which one is the correct one?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
