如何处理对在COM对象中实现IDisposable的对象的引用?

时间:2020-10-28 12:54:07

标签: c# .net com interop idisposable

假设我使用C#实现COM对象。它的成员之一是对实现IDisposable的对象的引用:

[ComVisible(true)]
[Guid(something)]
public class ComServerImpl
{

    private Stream someStream; // <<< this references an object which implements IDisposable
}

我希望在COM客户端调用IDisposable以便引用计数变为零时,处置实现IUnknown::Release()的对象。那是该对象可以有意义地使用的最新时间。我不能等待垃圾收集器运行,因为它可能会在以后发生。

如果我要使用C ++和ATL来实现COM服务器,我会使用CComObjectRootEx::FinalRelease()方法,但是用C#来实现COM服务器时,我看不到任何等效方法。

我如何及时处置stream成员?

0 个答案:

没有答案
相关问题