我正在开发一个ManagementEventWatcher
用于监视USB
事件的应用程序。代码可以正常工作,但在某些情况下程序会丢失一些USB events
. 列出 USB 中所有事件的正确方法是什么?
我正在使用以下代码,我正在使用两个查询来连接显示器并从 USB 分离。我需要监控许多 USB 端口。
USB 显示器
ManagementEventWatcher watchUSBattach = new ManagementEventWatcher();
ManagementEventWatcher watchUSBDettach = new ManagementEventWatcher();
WqlEventQuery queryUsbAttach = new WqlEventQuery("SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2 ");
watchUSBattach.EventArrived += new EventArrivedEventHandler(watchUSBEventAdd);
watchUSBattach.Query = queryUsbAttach;
watchUSBattach.Start();
WqlEventQuery queryUsbDettach = new WqlEventQuery("SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 3");
watchUSBDettach.EventArrived += new EventArrivedEventHandler(watchUSBEventDettach);
watchUSBDettach.Query = queryUsbDettach;
watchUSBDettach.Start();