diff --git a/adrilight/Util/SerialStream.cs b/adrilight/Util/SerialStream.cs index 370d6ec..10d9bcf 100644 --- a/adrilight/Util/SerialStream.cs +++ b/adrilight/Util/SerialStream.cs @@ -247,11 +247,18 @@ private void DoWork(object tokenObject) } //to be safe, we reset the serial port - if (serialPort != null && serialPort.IsOpen) + try { - serialPort.Close(); + if (serialPort != null && serialPort.IsOpen) + { + serialPort.Close(); + } + serialPort?.Dispose(); + } + catch (Exception) + { + // possible IoException when device is unplugged } - serialPort?.Dispose(); serialPort = null; //allow the system some time to recover