private int Callback(IntPtr context, IntPtr deviceProfile, HotplugEvent e, IntPtr userData) { //Task.Run(() => //{ if (e == HotplugEvent.DeviceArrived) { var newBoard = new TreehopperUsb(new LibUsbConnection(deviceProfile)); Debug.WriteLine("Adding " + newBoard); if (currentContext == null) { Boards.Add(newBoard); } else { currentContext.Post( delegate { Boards.Add(newBoard); }, null); } } else if (e == HotplugEvent.DeviceLeft) { var devicePath = deviceProfile.ToString(); Debug.WriteLine("Removing devicePath " + devicePath); RemoveDevice(devicePath); } //}); return(0); }
public static extern Error HotplugRegisterCallback(Context ctx, HotplugEvent events, HotplugFlag flags, int vendorId, int productId, int devClass, IntPtr Delegate, IntPtr userData, ref int callbackHandle);
internal static extern int HotplugRegisterCallback([In] IntPtr context, HotplugEvent events, int flags, int vendor_id, int product_id, int dev_class, HotplugCallbackFunction cb_fn, IntPtr user_data, IntPtr HandleRef);