Why don't COM object use IDisposable?

为什么COM对象在CLR Callable Wrappers中不使用IDisposable?


Presumably such an IDisposable implementation would call 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.

But as the documentation for Marshal.ReleaseComObject states, it should not be used in the general case - and probably not at all for in-proc COM objects. Here's a blog post with some more detailed info.

Hence it would not have been a good idea to encourage people to use it by calling it from an IDisposable implementation in the RCW.

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.

链接地址: http://www.djcxy.com/p/54854.html

上一篇: 使用SVG和Javascript交互式有向图

下一篇: 为什么COM对象不使用IDisposable?