我已经构建了一个使用ManagementEventWatcher
该类的 .net 库。我的库是一次性的,所以通常我会将它包装在 using 语句中,并且ManagementEventWatcher
该类将由我的库处理。
我的问题是我的库暴露给 COM,并在不使用一次性模式的 VB6 中使用。如果用户没有从他们的 .net 应用程序中调用库上的 dispose,或者由于 VB6 而不能调用,则该类将从内部ManagementEventWatcher
抛出一个InvalidComObjectException
SinkForEventQuery.Cancel
我无法捕获异常,所以它仍然未处理,这不好。我可以尝试一些解决方法吗?
System.Runtime.InteropServices.InvalidComObjectException was unhandled
Message=COM object that has been separated from its underlying RCW cannot be used.
Source=mscorlib
StackTrace:
at System.StubHelpers.StubHelpers.StubRegisterRCW(Object pThis, IntPtr pThread)
at System.Management.IWbemServices.CancelAsyncCall_(IWbemObjectSink pSink)
at System.Management.SinkForEventQuery.Cancel()
at System.Management.ManagementEventWatcher.Stop()
at System.Management.ManagementEventWatcher.Finalize()
InnerException: