steve highett

steve highett

  • NA
  • 2
  • 6.5k

USB C# WPF Interface interaction

Oct 13 2015 11:44 PM
'm creating a WPF C# application and apart of the program i want to add is where upon start up of application the application check if a specific usb is connected if so it allows interaction with the UI if not then the UI cannot be interacted till the usb is connected and if at any time the usb is removed the UI locks any interaction with the user till the usb is reconnected
the only problem ive so far to implanting this is that all usb detection code or methods are either outdated and useless or not what i need and all my attempts have failed 
All i need is for the application to detect when a specific usb is attached and removed i don't need notifications or anything like that just for the application to know and act according to if its connected or not
 
is my current way going down the right direction? 
 
this is what i have so far 
 
public class USBDetection
{
public const int WM_DEVICECHANGE = 0x0219;
public const int WM_DEVICEREMOVECOMPLETE = 0x8004;
public const int WM_DeviceAttached = 0x8000;
public delegate void USBDeviceEventHandler(Object sender, USBDeviceEventArgs e);
public event USBDeviceEventHandler USBDeviceAttached;
public event USBDeviceEventHandler USBDeviceRemoved;
public class USBDeviceEventArgs : EventArgs
{
public void USBDeviceAttached(Object sender, USBDeviceEventArgs e)
{
 // when Correct USB is attached interface can be interacted with
}
public void USBDeviceRemoved(Object sender, USBDeviceEventArgs e)
{
 // when USB is removed interface cannot be interacted with
}
}
}
 

Answers (1)