Why don't COM object use IDisposable?

浪子不回头ぞ 提交于 2019-12-10 04:03:13

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/7467632/why-dont-com-object-use-idisposable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!