added exception handling, fixes errors when waking up, or missing network
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user