WMI query and event works in single class but not application?
I am using WMI to find events where a USB device is plugged in. I made a
standalone class to try this out, and it worked great! As soon as I call
the class from my application, it does not work. The code is identical,
with the exception of the main() when I compile the class as a stand-alone
exe. The code follows:
ManagementScope scope = new ManagementScope("root\\CIMV2"); //set the
scope
WqlEventQuery query = new WqlEventQuery("SELECT * FROM
__InstanceCreationEvent WHERE TargetInstance ISA 'Win32_PnPEntity'");
//set the events
watcher = new ManagementEventWatcher(scope, query);
watcher.EventArrived += new
EventArrivedEventHandler(this.DeviceChangeEventReceived);
watcher.Start();
The DeviceChangeEventReceived method is never called when built into the
larger application. I thought it might be the scope, but it seems not to
be. I am sure that it's something simple, but I'm out of ideas. Thanks!
No comments:
Post a Comment