I subscribe to the WMI event and get the message "The COM object that was separated from its base RCW cannot be used" when my application closes. This question has been asked before , but it is very different from my circumstances.
I call this code from the main thread:
string strComputer = @".";
ManagementScope scope = new ManagementScope(@"\\" + strComputer + @"\root\wmi");
scope.Connect();
EventQuery query = new EventQuery("Select * from MSNdis_StatusMediaDisconnect");
ManagementEventWatcher watcher = new ManagementEventWatcher(scope, query);
watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
watcher.Start();
The event is reported correctly. I suspect the problem is how these objects are freed when my application closes. How to prevent a mistake? Do I have to explicitly delete the observer, scope and request before closing my application?