简体   繁体   English

如何在不依赖异常的情况下判断COM对象是否已与其基础RCW分离?

[英]how to tell if a COM object has been separated from its underlying RCW without relying on exceptions?

A way to tell if the COM Object's reference count has reached 0 is by attempting to access one of its members and catch the resulting InvalidComObjectException, which is not very elegant and doesn't seem to lend itself well. 判断COM对象的引用计数是否达到0的一种方法是尝试访问其中一个成员并捕获生成的InvalidComObjectException,这不是很优雅,并且似乎不能很好地适应。 Another way is to call Marshal.ReleaseComObject and check the result, but that requires that you decrease the Com Object's reference count by 1. 另一种方法是调用Marshal.ReleaseComObject并检查结果,但这需要将Com对象的引用计数减1。

Is there a straightforward way to tell ? 有简单明了的方法吗?

On the .NET forums, this question has been posed before. 在.NET论坛上,此问题已经提出过。

Q: Are there any approaches to get the Internal Reference Count without decrementing it? 问:有没有任何方法可以获得内部参考计数而不减少它?

A: There are no class library methods that can provide this service. 答:没有可以提供此服务的类库方法。

Q: If it's impossible to get the Internal Reference Count without decrementing it, Is there any way to increment its count after calling Marshal.ReleaseComObject() ? 问:如果在不减少内部引用计数的情况下获取内部引用计数是不可能的,那么在调用Marshal.ReleaseComObject()之后是否有任何方法可以增加其计数?

A: Again, there are no class library methods that provide this service. 答:同样,没有提供此服务的类库方法。

They do have an awkward way of achieving this as a workaround with global APIs exported from your COM server. 他们确实有一种笨拙的方法来实现这一点,作为从COM服务器导出的全局API的解决方法。
Details here: http://social.msdn.microsoft.com/Forums/vstudio/en-US/9de651e0-ad3c-44be-8855-3dc13673ac73/how-can-i-get-the-internal-marshaling-count-of-an-rcw-systemcomobject?forum=clr 详情请访问: http//social.msdn.microsoft.com/Forums/vstudio/en-US/9de651e0-ad3c-44be-8855-3dc13673ac73/how-can-i-get-the-internal-marshaling-count-of -an-RCW-systemcomobject?论坛= CLR

Other than that, looks like you are stuck. 除此之外,看起来你被卡住了。 Hope that helps you. 希望对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 已经与其基础RCW分离的COM对象无法使用 - 为什么会发生? - COM object that has been separated from its underlying RCW can not be used - why does it happen? 如何判断一个对象是否已被垃圾收集 - How to Tell If an Object Has Been Garbage Collected 如何判断任务是否被“观察到”? - How to tell if Task has been “observed”? 如何判断Socket何时断开连接 - How to tell when a Socket has been disconnected 从.Net传递到COM时,RCW不会转换整数 - RCW does not convert integer when passing from .Net to COM 有没有办法告诉DataReader是否已通过迭代而无需调用.Read()? - Is there a way to tell if a DataReader has been iterated through without calling .Read()? AWS .NET无法判断对象是否已成功删除 - AWS .NET no way to tell if an object has been successfully deleted 如何判断我的代码是否已从立即窗口调用? - How can I tell if my code has been called from the Immediate Window? 在 STA 线程中创建的 COM RWC 在线程终止时与底层 COM 对象断开连接是否正常? - Is it normal for COM RWC's created in STA thread to disconnect from the underlying COM object on thread termination? 我怎么知道ILMerge已被使用 - How can I tell that ILMerge has been used
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM