How can I wrap a COM object in a native .NET class?

后端 未结 4 1025
醉梦人生
醉梦人生 2021-02-05 10:53

I\'m using an extensive existing COM API (could be Outlook, but it\'s not) in .NET (C#). I\'ve done this by adding a \"COM Reference\" in Visual Studio so all the \"magic\" is

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-05 11:38

    The biggest problem I've found with bringing COM objects into .NET is the fact that the garbage collector runs on a different thread and the final release of the COM object will often (always?) be called from that thread.

    Microsoft deliberately broke the COM threading model rules here which state that with apartment threaded objects, all methods must be called from the same thread.

    For some COM libraries this is not a big deal, but for others it's a huge problem - particularly for libraries that need to release resources in their destructors.

    Something to be aware of...

提交回复
热议问题