I have had a C# program running on Windows 7 which subscribes to USB insert/remove events with no problems (using the WMI API). On a Windows 10 machine the same program use excessive CPU. So I wonder, have the WMI implementation changed in Windows 10? See program code below:
WqlEventQuery insertUSBDeviceQuery = new WqlEventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_PnPEntity'");
insertWatcher = new ManagementEventWatcher(insertUSBDeviceQuery);
insertWatcher.EventArrived += new EventArrivedEventHandler(DeviceInsertedEvent);
insertWatcher.Start();
On Windows 10 this cause the WmiPrvSE.exe (WMI Provider Host) process to use roughly 30% of the CPU.
Any other ideas why we see a difference between Windows 7 & 10 here?
We did not find an answer to this problem. But since we knew exactly what devices we were looking for we ended up polling for data every 5s using this query.
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"select DeviceID from Win32_PnPEntity Where DeviceID Like 'USB\\VID_" + vid + "&PID_" + pid + "%'"))
This was much more efficient and did not cause any CPU usage problems.