Click here to Skip to main content
15,867,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

Library Class:
A USB Library to Detect USB Devices[^]

How can I get only one Event Notification when USB Arrived or Removed when using the class above! Any help will be greatly appreciated!

Thanks!

What I have tried:

C#
USBClass usb = new USBClass();
USBDevicePropertiesList = new List<USBClass.DeviceProperties>();
usb.USBDeviceAttached += USBPort_USBDeviceAttached;
usb.USBDeviceRemoved += Usb_USBDeviceRemoved;
usb.RegisterForDeviceChange(true, Handle);


On USBPort_USBDeviceAttached,I always get two event when USB Arrived

On Usb_USBDeviceRemoved,I always get two event when USB Removed
Posted
Updated 21-Oct-19 22:59pm
v2

Please post your question in the forum at the end of the article so the author may help you.
 
Share this answer
 
Comments
TabZhang 22-Oct-19 5:56am    
Already post there, thanks!
Pretty sure that because you get two alerts, and I get 4, the code scans all usb ports when an item is connected or disconnected.
 
Share this answer
 
Comments
TabZhang 22-Oct-19 5:59am    
Yes, I have received it four times.

Do you have some solution that can fix it, and share it with me here? thanks!
Andy Lanng 22-Oct-19 6:50am    
I don't have time to code it code it for you, but I suggest you keep track of when your specific device is connected, then when a device is removed and none of the connected devices are your device then disconnect it.

The events fire for each usb port. it's up to you to decide what to do when you device is connected or not
TabZhang 22-Oct-19 22:33pm    
OK, Thanks for your suggestion!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900