Fixed non catched exception

main
Thomas Woischnig 2023-12-04 21:10:10 +01:00
parent cee5a4cf4f
commit 9a25ee86e8
3 changed files with 32 additions and 18 deletions

View File

@ -13,5 +13,10 @@ namespace Lobbies
/// The ip address the connection succeeded on /// The ip address the connection succeeded on
/// </summary> /// </summary>
public IPAddress? IPAddress { get; internal set; } public IPAddress? IPAddress { get; internal set; }
/// <summary>
/// If failed contains a error message reason
/// </summary>
public string? ErrorMessage { get; internal set; }
} }
} }

View File

@ -278,7 +278,10 @@ namespace Lobbies
{ {
return Task.Run(() => return Task.Run(() =>
{ {
string? error = string.Empty;
IPAddress? ret = null; IPAddress? ret = null;
try
{
using (var waitForIpEvent = new AutoResetEvent(false)) using (var waitForIpEvent = new AutoResetEvent(false))
using (var udpEchoClient = new UdpEchoServer()) using (var udpEchoClient = new UdpEchoServer())
{ {
@ -300,10 +303,16 @@ namespace Lobbies
udpEchoClient.CheckConnectionPossible(new IPEndPoint(ip, tryPort)); udpEchoClient.CheckConnectionPossible(new IPEndPoint(ip, tryPort));
} }
waitForIpEvent.WaitOne(500); if(!waitForIpEvent.WaitOne(500))
error = $"Timeout";
}
}
catch (Exception ex)
{
error = $"Exception: {ex}";
} }
events.Enqueue(new LobbyClientEvent { EventType = LobbyClientEventTypes.DirectConnectionTestComplete, EventData = new DirectConnectionTestResult { DirectConnectionPossible = ret != null, IPAddress = ret } }); events.Enqueue(new LobbyClientEvent { EventType = LobbyClientEventTypes.DirectConnectionTestComplete, EventData = new DirectConnectionTestResult { DirectConnectionPossible = ret != null, IPAddress = ret, ErrorMessage = error } });
}); });
} }