From 0bbeeac4d50f7dc25dd399477bc56ccea836e835 Mon Sep 17 00:00:00 2001 From: Generoso Martello Date: Tue, 18 Aug 2015 20:43:32 +0200 Subject: [PATCH] small fix to reader task disposing --- SerialPortLib/SerialPort.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SerialPortLib/SerialPort.cs b/SerialPortLib/SerialPort.cs index 193f65b..95b821b 100644 --- a/SerialPortLib/SerialPort.cs +++ b/SerialPortLib/SerialPort.cs @@ -103,7 +103,8 @@ public void Disconnect() { watcherTokenSource.Cancel(); connectionWatcher.Wait(5000); - connectionWatcher.Dispose(); + if (connectionWatcher != null) + connectionWatcher.Dispose(); connectionWatcher = null; watcherTokenSource = null; } @@ -224,7 +225,8 @@ private void Close() { readerTokenSource.Cancel(); readerTask.Wait(5000); - readerTask.Dispose(); + if (readerTask != null) + readerTask.Dispose(); readerTask = null; readerTokenSource = null; }