Exemple #1
0
        private static void MonitorDeviceChanges()
        {
            try
            {
                var deviceArrivalQuery = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2");

                var deviceRemovalQuery = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 3");

                _arrival = new ManagementEventWatcher(deviceArrivalQuery);
                _removal = new ManagementEventWatcher(deviceRemovalQuery);

                _arrival.EventArrived += (o, args) => RaisePortsChangedIfNecessary(EventType.Insertion);
                _removal.EventArrived += (sender, eventArgs) => RaisePortsChangedIfNecessary(EventType.Removal);

                // Start listening for events.
                _arrival.Start();
                _removal.Start();
            }
            catch (ManagementException err)
            {
                Tools._writeDebugDiagnosticExceptionMessage(err.Message);
            }
        }
Exemple #2
0
 public static void _EXLOG(this string format, params object[] args)
 {
     Tools._writeDebugDiagnosticExceptionMessage(Tools.FormatStr(format, args));
 }