Skip to content

Commit

Permalink
Fixed: Potential Exception after Application with Server Quits
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Nov 6, 2022
1 parent 76e8c49 commit 457b74f
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public ReloadedAppViewModel(ApplicationViewModel applicationViewModel)
ApplicationViewModel.SelectedProcess.Exited += SelectedProcessOnExited;

/* Try establish connection. */
if (!TryGetPort(out _port))
if (!TryGetPort(true, out _port))
return;

Client = new LiteNetLibClient(IPAddress.Loopback, "", _port, true);
Client.OnTryReconnect += (peer) => TryGetPort(out _port);
Client.OnTryReconnect += (peer) => TryGetPort(false, out _port);
Client.OverrideDetailsOnReconnect += () => (null, _port);
Client.OnReceiveException += ClientOnReceiveException;

Expand All @@ -60,7 +60,7 @@ public ReloadedAppViewModel(ApplicationViewModel applicationViewModel)
_refreshTimer.Enabled = true;
}

private bool TryGetPort(out int port)
private bool TryGetPort(bool throwOnFailure, out int port)
{
try
{
Expand All @@ -70,7 +70,9 @@ private bool TryGetPort(out int port)
catch (Exception ex)
{
port = -1;
Errors.HandleException(new Exception(Resources.ErrorFailedToObtainPort.Get(), ex));
if (throwOnFailure)
Errors.HandleException(new Exception(Resources.ErrorFailedToObtainPort.Get(), ex));

return false;
}
}
Expand Down

0 comments on commit 457b74f

Please sign in to comment.