From 8c92e7092f5ffe362fd795afee7de21d82ef0326 Mon Sep 17 00:00:00 2001 From: Edward Wright Date: Sun, 15 Sep 2019 20:36:47 -0400 Subject: [PATCH] fix for unhandled exception on com port disconnect --- Installer-System/Installer-System.aip | 4 ++-- Installer/Installer.aip | 4 ++-- SimplySerial/SimplySerial.cs | 11 +++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Installer-System/Installer-System.aip b/Installer-System/Installer-System.aip index 84dc113..6751a42 100644 --- a/Installer-System/Installer-System.aip +++ b/Installer-System/Installer-System.aip @@ -15,10 +15,10 @@ - + - + diff --git a/Installer/Installer.aip b/Installer/Installer.aip index 4cba8a7..4e6c0b5 100644 --- a/Installer/Installer.aip +++ b/Installer/Installer.aip @@ -15,10 +15,10 @@ - + - + diff --git a/SimplySerial/SimplySerial.cs b/SimplySerial/SimplySerial.cs index db35230..2faa564 100644 --- a/SimplySerial/SimplySerial.cs +++ b/SimplySerial/SimplySerial.cs @@ -10,7 +10,7 @@ namespace SimplySerial { class SimplySerial { - static readonly string version = "0.4.0"; + static readonly string version = "0.4.1"; static List availablePorts; static SerialPort serialPort; @@ -208,7 +208,14 @@ namespace SimplySerial ExitProgram((e.GetType() + " occurred while attempting to read/write to/from " + port.name + "."), exitCode: -1); else Output("\n<<< Communications Interrupted >>>\n"); - serialPort.Dispose(); + try + { + serialPort.Dispose(); + } + catch (Exception ex) + { + //nothing to do here, other than prevent execution from stopping if dispose() throws an exception + } Thread.Sleep(2000); // sort-of arbitrary delay - should be long enough to read the "interrupted" message Console.Clear(); if (autoConnect == AutoConnect.ANY)