[英]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.