private void Main_Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (_sp.IsOpen) { TransferData(new byte[513]); } if (_sp != null) { if (_sp.IsOpen) { TransferData(new byte[513]); } _sp.Dispose(); } if (_newDeviceUI != null) { _newDeviceUI.Close(); } logger.Warn("Closing application....."); logger = null; }