Catch USB plug and unplug event System.InvalidCastException
问题 I'm trying to detect USB device insertion and remove with WinForm desktop C# application: public Form1() { InitializeComponent(); USB(); } then: private void USB() { WqlEventQuery weqQuery = new WqlEventQuery(); weqQuery.EventClassName = "__InstanceOperationEvent"; weqQuery.WithinInterval = new TimeSpan(0, 0, 3); weqQuery.Condition = @"TargetInstance ISA 'Win32_DiskDrive'"; var m_mewWatcher = new ManagementEventWatcher(weqQuery); m_mewWatcher.EventArrived += new EventArrivedEventHandler(m