added exception handling, fixes errors when waking up, or missing network

This commit is contained in:
2026-01-18 14:48:32 +01:00
parent c1d7ba4b3d
commit b8d5e25352
3 changed files with 62 additions and 8 deletions

View File

@@ -46,9 +46,30 @@ public class UdpSender : IDisposable
public void SendFloats(float[] values)
{
string packet = string.Join(",", values);
byte[] data = System.Text.Encoding.ASCII.GetBytes(packet);
client.Send(data, data.Length, endpoint);
try
{
string packet = string.Join(",", values);
byte[] data = System.Text.Encoding.ASCII.GetBytes(packet);
client.Send(data, data.Length, endpoint);
}
catch (SocketException ex) when (
ex.SocketErrorCode == SocketError.NetworkUnreachable ||
ex.SocketErrorCode == SocketError.HostUnreachable ||
ex.SocketErrorCode == SocketError.NetworkDown ||
ex.SocketErrorCode == SocketError.AddressNotAvailable)
{
// Network not ready (sleep, reconnecting, etc.)
// Skip this tick silently.
}
catch (ObjectDisposedException)
{
// App is shutting down — ignore.
}
catch (Exception)
{
// Any other unexpected error — swallow to avoid crashing the tray app.
}
}
public void Dispose()