make sure iw4madmin exits when selecting "no" to continue with failed server connections

This commit is contained in:
RaidMax 2022-02-28 15:16:30 -06:00
parent edf8e03b04
commit 58d48a211e
2 changed files with 13 additions and 5 deletions

View File

@ -66,8 +66,8 @@ namespace IW4MAdmin.Application.IO
}
return Task.FromResult(Enumerable.Empty<GameEvent>());
}
new Thread(() => ReadNetworkData(client)).Start();
Task.Run(async () => await ReadNetworkData(client, _token), _token);
}
catch (Exception ex)
{
@ -111,9 +111,9 @@ namespace IW4MAdmin.Application.IO
return Task.FromResult((IEnumerable<GameEvent>)events);
}
private void ReadNetworkData(UdpClient client)
private async Task ReadNetworkData(UdpClient client, CancellationToken token)
{
while (!_token.IsCancellationRequested)
while (!token.IsCancellationRequested)
{
// get more data
IPEndPoint remoteEndpoint = null;
@ -127,7 +127,13 @@ namespace IW4MAdmin.Application.IO
try
{
bufferedData = client.Receive(ref remoteEndpoint);
var result = await client.ReceiveAsync(_token);
remoteEndpoint = result.RemoteEndPoint;
bufferedData = result.Buffer;
}
catch (OperationCanceledException)
{
_logger.LogDebug("Stopping network log receive");
}
catch (Exception ex)
{

View File

@ -153,6 +153,8 @@ namespace IW4MAdmin.Application
{
Console.WriteLine(e.Message);
}
_serverManager?.Stop();
Console.WriteLine(exitMessage);
await Console.In.ReadAsync(new char[1], 0, 1);