We had a COM Object that needed to have ReleaseComObject called on it. This worked fine, and happily for a while. Then, someone created a .NET object with the exact same signature so that it might easily replace the use of the COM object. However, this new assemebly is NOT a COM Object, so it's extraordinarily bad to call ReleaseComObject on it (in that it totally doesn't work.)
我们有一个需要调用ReleaseComObject的COM对象。 这个工作很好,并且很高兴有一段时间。 然后,有人创建了一个具有完全相同签名的.NET对象,以便可以轻松替换COM对象的使用。 但是,此新组件不是COM对象,因此在其上调用ReleaseComObject非常不好(因为它完全不起作用)。
So, here's a good best practice if you're doing some crazy crap like this:
因此,如果您像这样疯狂地胡扯,这是一个很好的最佳实践:
if(Marshal.IsComObject(foo)) Marshal.ReleaseComObject(foo);
if(Marshal.IsComObject(foo))Marshal.ReleaseComObject(foo);
翻译自: https://www.hanselman.com/blog/releasecomobject-and-iscomobject