/* example:
         * monitor_usb_devices("Win32_USBControllerDevice");
         * monitor_usb_devices("Win32_USBHub");
         */
        public static void monitor_usb_devices(string usb_class)
        {
            var md = new DeviceMonitor()
            {
                DeviceAddedEvent = on_DeviceAddedEvent_dump_info, DeviceDeletedEvent = OnDeletedDevice_dump_info
            };

            md.Monitor(usb_class);
            Thread.Sleep(2000000);
        }
        private PDManager()
        {
            var existing_devices = DeviceFinder.FindObjects("Win32_USBHub");

            foreach (var device in existing_devices)
            {
                if (device.ContainsKey("PNPDeviceID"))
                {
                    var    device_id = device["PNPDeviceID"];
                    string VidPid = "", UniqueId = "";
                    if (USBUtil.pnp_device_id_to_vidpid_and_unique_id(device_id, ref VidPid, ref UniqueId))
                    {
                        lock (this)
                            vidpid_to_unique_id_.Add(VidPid, UniqueId);
                    }
                }
            }
            var existing_controller_devices = DeviceFinder.FindObjects("Win32_USBControllerDevice");

            foreach (var device in existing_controller_devices)
            {
                if (device.ContainsKey("Dependent"))
                {
                    var    device_id = device["Dependent"];
                    string VidPid = "", UniqueId = "";
                    if (USBUtil.dependent_to_vidpid_and_unique_id(device_id, ref VidPid, ref UniqueId))
                    {
                        lock (this)
                            if (!vidpid_to_unique_id_.ContainsKey(VidPid))
                            {
                                vidpid_to_unique_id_.Add(VidPid, UniqueId);
                            }
                    }
                }
            }

            Refresh();

            monitor_usbhub_devices_.DeviceAddedEvent   += DeviceAdded;
            monitor_usbhub_devices_.DeviceDeletedEvent += DeviceRemoved;
            monitor_usbhub_devices_.Monitor("Win32_USBHub");

            monitor_controller_devices_.DeviceAddedEvent   += DeviceAddedConroller;
            monitor_controller_devices_.DeviceDeletedEvent += DeviceRemovedConroller;
            monitor_controller_devices_.Monitor("Win32_USBControllerDevice");

            new Thread(Win32Util.check_for_dialogs_thread)
            {
                IsBackground = true
            }.Start();
        }