From b5a8ae5d56152c72c6c6d3c97375a53dcaa0da4d Mon Sep 17 00:00:00 2001 From: Jerker Dahlblom Date: Sun, 3 Dec 2023 19:00:55 +0200 Subject: [PATCH] Closing properly when socket comms fails --- src/client/DCSInsight/Communication/TCPClientHandler.cs | 1 + src/client/DCSInsight/MainWindow.xaml.cs | 7 +++++++ src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs | 5 ++--- .../UserControls/UserControlLoSetCommandAPI.xaml.cs | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/client/DCSInsight/Communication/TCPClientHandler.cs b/src/client/DCSInsight/Communication/TCPClientHandler.cs index 480983d..f05b675 100644 --- a/src/client/DCSInsight/Communication/TCPClientHandler.cs +++ b/src/client/DCSInsight/Communication/TCPClientHandler.cs @@ -101,6 +101,7 @@ private async void ClientThread() catch (SocketException ex) { Logger.Error(ex); + break; } } diff --git a/src/client/DCSInsight/MainWindow.xaml.cs b/src/client/DCSInsight/MainWindow.xaml.cs index 01324a7..a0b2b24 100644 --- a/src/client/DCSInsight/MainWindow.xaml.cs +++ b/src/client/DCSInsight/MainWindow.xaml.cs @@ -140,6 +140,13 @@ public void ConnectionStatus(ConnectionEventArgs args) try { _isConnected = args.IsConnected; + if (!_isConnected) + { + Dispatcher?.BeginInvoke((Action)(Disconnect)); + Dispatcher?.BeginInvoke((Action)(SetFormState)); + return; + } + Dispatcher?.BeginInvoke((Action)(() => SetConnectionStatus(args.IsConnected))); Dispatcher?.BeginInvoke((Action)(SetFormState)); ; } diff --git a/src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs b/src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs index 5cc9380..fa3c675 100644 --- a/src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs +++ b/src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs @@ -175,7 +175,6 @@ protected override void BuildUI() VerticalAlignment = VerticalAlignment.Center }; ComboBoxPollTimes.DataContextChanged += ComboBoxPollTimes_OnDataContextChanged; - ComboBoxPollTimes.Items.Add(50); ComboBoxPollTimes.Items.Add(100); ComboBoxPollTimes.Items.Add(500); ComboBoxPollTimes.Items.Add(1000); @@ -206,7 +205,8 @@ public override void SetResult(DCSAPI dcsApi) Dispatcher?.BeginInvoke((Action)(() => LabelResult.Content = $"Result ({dcsApi.ResultType})")); var result = dcsApi.ErrorThrown ? dcsApi.ErrorMessage : (string.IsNullOrEmpty(dcsApi.Result) ? "nil" : dcsApi.Result); - + + AutoResetEventPolling.Set(); if (KeepResults) { Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = TextBoxResult.Text.Insert(0, "\n---\n"))); @@ -214,7 +214,6 @@ public override void SetResult(DCSAPI dcsApi) return; } Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = result)); - AutoResetEventPolling.Set(); } catch (Exception ex) { diff --git a/src/client/DCSInsight/UserControls/UserControlLoSetCommandAPI.xaml.cs b/src/client/DCSInsight/UserControls/UserControlLoSetCommandAPI.xaml.cs index 0957dcf..df6e4f2 100644 --- a/src/client/DCSInsight/UserControls/UserControlLoSetCommandAPI.xaml.cs +++ b/src/client/DCSInsight/UserControls/UserControlLoSetCommandAPI.xaml.cs @@ -240,6 +240,8 @@ public override void SetResult(DCSAPI dcsApi) Dispatcher?.BeginInvoke((Action)(() => LabelResult.Content = $"Result ({dcsApi.ResultType})")); var result = dcsApi.ErrorThrown ? dcsApi.ErrorMessage : (string.IsNullOrEmpty(dcsApi.Result) ? "nil" : dcsApi.Result); + + AutoResetEventPolling.Set(); if (KeepResults) { @@ -248,7 +250,6 @@ public override void SetResult(DCSAPI dcsApi) return; } Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = result)); - AutoResetEventPolling.Set(); } catch (Exception ex) {