From 7c6f50f85c0e0176354e7f9ce18658e8fd5698a7 Mon Sep 17 00:00:00 2001 From: LeiYangGH <675686066@qq.com> Date: Thu, 2 Mar 2017 22:26:47 +0800 Subject: [PATCH] set _rxThread to Background thread, making sure it will exit when the main(UI) thread exits --- PInvokeSerialPort/SerialPort.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PInvokeSerialPort/SerialPort.cs b/PInvokeSerialPort/SerialPort.cs index c9d1021..5d8a644 100755 --- a/PInvokeSerialPort/SerialPort.cs +++ b/PInvokeSerialPort/SerialPort.cs @@ -109,6 +109,8 @@ namespace PInvokeSerialPort Name = "CommBaseRx", Priority = ThreadPriority.AboveNormal }; + //If not set to true, my application process will not exit completely after UI closed + _rxThread.IsBackground = true; _rxThread.Start(); Thread.Sleep(1); //Give rx thread time to start. By documentation, 0 should work, but it does not!