private void closeConnect() { try { sms.ClosePort(serialPort); serialPort = null; } catch (Exception ex) { File.AppendAllText(@"C:\netmd.log", "Message: " + ex.Message + " - closeConnect\r\n"); File.AppendAllText(@"C:\netmd.log", "StackTrace: " + ex.StackTrace + "\r\n"); File.AppendAllText(@"C:\netmd.log", "========================================================\r\n"); } finally { serialPort = null; } }