如何检测 USB 断开连接事件?(Windows、.NET C# 应用程序)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/541765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:06:54  来源:igfitidea点击:

How can I detect a USB disconnect event? (Windows, .NET C# application)

.neteventsusbdisconnect

提问by Jon

Currently how I do this is I poll for a masked list of USB devices (masked specifically for the device I'm working with) and if it's there, I continue, if not then I notify the user that the device is not connected. The method for getting a list of USB devices is provided for me through a USB peripheral controller chip manufacturer's .NET library.

目前我的做法是轮询 USB 设备的屏蔽列表(专门为我正在使用的设备屏蔽),如果它在那里,我继续,如果没有,我会通知用户该设备未连接。通过USB外围控制器芯片制造商的.NET库为我提供了获取USB设备列表的方法。

Is there an event somewhere for a USB device disconnect?

某处是否有 USB 设备断开连接的事件?

回答by Jose Vega

have you checked out the Win32_USBControllerDevice class? http://msdn.microsoft.com/en-us/library/aa394505(VS.85).aspx

你检查过 Win32_USBControllerDevice 类吗? http://msdn.microsoft.com/en-us/library/aa394505(VS.85).aspx