Skip to content

Commit

Permalink
Closing properly when socket comms fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jdahlblom committed Dec 3, 2023
1 parent 0aee0e1 commit b5a8ae5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/client/DCSInsight/Communication/TCPClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private async void ClientThread()
catch (SocketException ex)
{
Logger.Error(ex);
break;
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/client/DCSInsight/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)); ;
}
Expand Down
5 changes: 2 additions & 3 deletions src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -206,15 +205,15 @@ 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")));
Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = TextBoxResult.Text.Insert(0, result)));
return;
}
Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = result));
AutoResetEventPolling.Set();
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -248,7 +250,6 @@ public override void SetResult(DCSAPI dcsApi)
return;
}
Dispatcher?.BeginInvoke((Action)(() => TextBoxResult.Text = result));
AutoResetEventPolling.Set();
}
catch (Exception ex)
{
Expand Down

0 comments on commit b5a8ae5

Please sign in to comment.