Ejemplo n.º 1
0
        private void DeviceEvent(object sender, EventArrivedEventArgs e)
        {
            (sender as ManagementEventWatcher)?.Stop();

            if (!(e.NewEvent["TargetInstance"] is ManagementBaseObject instance))
            {
                return;
            }

            var deviceDisconnected = e.NewEvent.ClassPath.ClassName.Equals("__InstanceDeletionEvent");

            if (deviceDisconnected)
            {
                _usb.DetectBootloader(instance, false);
            }
            else if (_usb.DetectBootloader(instance) && autoflashCheckbox.Checked)
            {
                flashButton_Click(sender, e);

                if (flashWhenReadyCheckbox.Checked)
                {
                    Invoke(new Action(() => flashWhenReadyCheckbox.Checked = false));
                }
            }

            UpdateHidDevices(deviceDisconnected);
            (sender as ManagementEventWatcher)?.Start();
        }
Ejemplo n.º 2
0
        private void DeviceEvent(object sender, EventArrivedEventArgs e)
        {
            (sender as ManagementEventWatcher)?.Stop();

            if (!(e.NewEvent["TargetInstance"] is ManagementBaseObject instance))
            {
                return;
            }

            var deviceDisconnected = e.NewEvent.ClassPath.ClassName.Equals("__InstanceDeletionEvent");

            if (deviceDisconnected)
            {
                _usb.DetectBootloader(instance, false);
            }
            else if (_usb.DetectBootloader(instance) && windowState.AutoFlashEnabled)
            {
                flashButton_Click(sender, e);
            }

            UpdateHidDevices(deviceDisconnected);
            (sender as ManagementEventWatcher)?.Start();

            if (!windowState.AutoFlashEnabled)
            {
                this.Invoke(new Action(EnableUI));
            }
        }