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. 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.
Is there a straightforward way to tell ?
On the .NET forums, this question has been posed before.
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()
?
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.
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
Other than that, looks like you are stuck. Hope that helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With