Beispiel #1
0
        public DeviceDetector(MessageHandler handler, Form form)
        {
            this.handler = handler;
            this.form    = form;
            usbQuery     = new WMIUsbQuery();

            usbQuery.AddUSBEventWatcher(USBEventHandler, USBEventHandler, new TimeSpan(0, 0, 3));

            Thread thread = new Thread(new ParameterizedThreadStart(this.updateDeviceCount));

            thread.Start(null);
        }
Beispiel #2
0
        private void USBEventHandler(Object sender, EventArrivedEventArgs e)
        {
            if (e.NewEvent.ClassPath.ClassName == "__InstanceCreationEvent" || e.NewEvent.ClassPath.ClassName == "__InstanceDeletionEvent")
            {
                ManagementBaseObject mbo = e.NewEvent["TargetInstance"] as ManagementBaseObject;

                if (mbo != null && mbo.ClassPath.ClassName == "Win32_USBControllerDevice")
                {
                    String dependent = (mbo["Dependent"] as String).Split(new Char[] { '=' })[1];

                    // string VIDPID = "VID_" + vid.ToString("X4") + "&PID_" + pid.ToString("X4") + "&MI_" + mi.ToString("D2");


                    deviceCount = WMIUsbQuery.GetDeviceCount();

                    form.Invoke(handler, Messages.MSG_UPDATE_DEVICE_COUNT, deviceCount);
                }
            }
        }
Beispiel #3
0
 private void updateDeviceCount(object o)
 {
     deviceCount = WMIUsbQuery.GetDeviceCount();
     form.Invoke(handler, Messages.MSG_UPDATE_DEVICE_COUNT, deviceCount);
 }