/// <summary> /// Close all handles to the device and unregisters device removal notification. /// </summary> private void CloseDevice() { DebugWriteLine("CloseDevice()"); _deviceAvailable = false; if (_readHandle == null && _writeHandle == null) { DebugWriteLine("Device already closed"); return; } if (_readHandle != null) { _notifyWindow.UnregisterDeviceRemoval(); _readHandle.DangerousRelease(); _readHandle.Dispose(); _readHandle = null; } if (_writeHandle != null) { _writeHandle.Dispose(); _writeHandle = null; } }