TargetInstance ISA'Win32_SerialPort'“

时间:2011-08-19 09:54:16

标签: c# windows serial-port wmi

C#,WPF,Windows 7,PC,Visaul Studio 2010

当用户通过执行此操作将COM端口连接到PC时,我尝试陷阱

            myCOMAddEventQue = new WqlEventQuery("__InstanceCreationEvent", "TargetInstance ISA 'Win32_SerialPort'");
            myCOMAddEventQue.WithinInterval = TimeSpan.FromSeconds(1);
            myCOMAddWatcher = new ManagementEventWatcher(myCOMAddEventQue);
            myCOMAddWatcher.EventArrived += new EventArrivedEventHandler(COMAddEvent);
            myCOMAddWatcher.Start();

但这会产生错误“ObjectDisposedException未处理”??

我可以通过

捕获USB记忆棒
            myDiscAddlEventQue = new WqlEventQuery("__InstanceCreationEvent", "TargetInstance ISA 'Win32_LogicalDisk' and (TargetInstance.DriveType = 2 or TargetInstance.DriveType = 4)");

为什么Windows会为COM端口生成错误?

关心Stefan

0 个答案:

没有答案