C#, WPF, Windows 7, PC, Visaul Studio 2010
I try to trap when the user attach a COM port to the PC by doing this
myCOMAddEventQue = new WqlEventQuery("__InstanceCreationEvent", "TargetInstance ISA 'Win32_SerialPort'");
myCOMAddEventQue.WithinInterval = TimeSpan.FromSeconds(1);
myCOMAddWatcher = new ManagementEventWatcher(myCOMAddEventQue);
myCOMAddWatcher.EventArrived += new EventArrivedEventHandler(COMAddEvent);
myCOMAddWatcher.Start();
But this generates the error "ObjectDisposedException was unhandled" ??
I am able to trap USB memorysticks by
myDiscA开发者_如何转开发ddlEventQue = new WqlEventQuery("__InstanceCreationEvent", "TargetInstance ISA 'Win32_LogicalDisk' and (TargetInstance.DriveType = 2 or TargetInstance.DriveType = 4)");
Why are Windows generating the error for the COM port?
Regards Stefan
精彩评论