There are those [MTAThread]
and [STAThread]
attributes which control the apartment threading model for COM in .Net applications, and from my own (very limited) testing, CoInitializeEx()
returns 1
(S_FALSE
) if called from the main thread of a console C# application.
According to Microsoft documentation, S_FALSE
means "The COM library is already initialized on this thread".
What I am wondering is whether there is actually a contractual guarantee in the framework itself that COM is going to be initialized on every .Net (Framework or Core application) thread?
If so, is it also guaranteed that all threads will be initialized with the same (STA or MTA) model?
I am asking this because for DirectShow applications it is crucial that COM is initialized on every thread, and I would like to avoid peppering the code with redundant calls to CoInitializeEx()
and CoUnitialize()
if those are already implicitly handled by the framework.