ReleaseComObject和IsComObject

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>