private void Window_Loaded(object sender, RoutedEventArgs e) { //HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); //source.AddHook(new HwndSourceHook(WindowMessageHelper.WndProc)); // Adds the windows message processing hook and registers USB device add/removal notification. HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); if (source != null) { var windowHandle = source.Handle; source.AddHook(HwndHandler); UsbNotification.RegisterUsbDeviceNotification(windowHandle); } }
private void MainWindow_Closed(object sender, EventArgs e) { UsbNotification.UnregisterUsbDeviceNotification(); }