none
Managed COM vs Native COM ThreadingModel RRS feed

  • Question

  • Hi, 

    I'm new to COM world.

    Here is an interesting situation that I'm facing!

    Case-1 : Two COM Object(one Managed COMObject and other UnManaged COMObject) both are registered to STA(ThreadingModel=Apartment). Managed COM object invokes a method on unmanaged COM object from different threads. In this case, it is observed that unmanaged COM Object executes calls from the thread that i has created on, though it receives calls from different threads. This works as expected, since COM classes is registered for STA.

    Case-2 : Two COM Object(one Managed COMObject and other UnManaged COMObject) both are registered to STA(ThreadingModel=Apartment). Unmanaged COM object invokes a method on Managed COM object from different threads. In this case, it is observed that managed COM Object executes calls from different threads. This surprises me. I was expecting the same results as i see with "Case-1" as both COM classes registers as STA.

    Since this invovles both .NET and COM world I have selected .NET forum.

    Am i missing something!

    Any suggestions are greatly appreciated.


    Thanks

    Suneel

    Sunday, November 1, 2015 10:14 AM

Answers

All replies

  • Hi thisissuneel,

    .NET component is Context agile and always executes in the caller's thread. See the detail information from below link.
    http://www.codeproject.com/Articles/990/Understanding-Classic-COM-Interoperability-With-NE#Affinity

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, November 2, 2015 3:24 AM
    Moderator
  • Hi Li Wang,

    Thanks for the information!

    So, for .NET COM Components setting "InprocServer32\ThreadingModel=Apartment" does not have any effect. Irrespective of Threading Model(either STA/MTA) .NET COM components will always execute on callers thread even when the callers thread is different from the thread that COM instance is created on.

    Is my understanding correct?

    Thanks

    Suneel

    Monday, November 2, 2015 8:41 AM
  • Hi thisissuneel,

    >>Is my understanding correct?

    Yes, you are right.

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, November 2, 2015 9:37 AM
    Moderator