本文介绍了为什么COM对象不使用IDisposable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么COM对象在其CLR可调用包装器中不使用IDisposable?

Why don't COM object use IDisposable in their CLR Callable Wrappers?

推荐答案

大概是这样的 IDisposable 实现将调用。

Presumably such an IDisposable implementation would call Marshal.ReleaseComObject.

在某些情况下,调用Marshal.ReleaseComObject是一个好主意,例如。

There are cases where calling Marshal.ReleaseComObject is a good idea, for example to get an Office application to quit after automation from a .NET client.

但是,正如 Marshal.ReleaseComObject 的文档所述,一般情况下不应使用它-可能根本不使用它。 -proc COM对象。 ,尽管文档有点稀疏。

However, what's interesting is that the Silverlight 4 AutomationFactory.CreateObject method does return a dynamic object that is IDisposable. And tests seem to show that this does in fact release the COM reference, though documentation is a bit sparse.

这篇关于为什么COM对象不使用IDisposable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 22:37