diff --git a/Service/Led/LedClient.cs b/Service/Led/LedClient.cs index 53e20fd..6047cea 100644 --- a/Service/Led/LedClient.cs +++ b/Service/Led/LedClient.cs @@ -135,45 +135,39 @@ public class LedClient _socket = null; } } - - private static readonly object Locker = new object(); private static bool InnerSend(byte[] bytes) { - lock (Locker) + if (_socket?.Connected ?? false) { + try + { + _socket.Send(bytes); + Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)}"); + return true; + } + catch (SocketException ex) + { + Log.Error($"Failed to send data. Reason: {ex.Message}"); + + return false; + } + } + else + { + Connect(); if (_socket?.Connected ?? false) { - try - { - _socket.Send(bytes); - Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)}"); - return true; - } - catch (SocketException ex) - { - Log.Error($"Failed to send data. Reason: {ex.Message}"); - - return false; - } + _socket.Send(bytes); + Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)} after reconnect"); + return true; } else { - - Connect(); - if (_socket?.Connected ?? false) - { - _socket.Send(bytes); - Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)} after reconnect"); - return true; - } - else - { - Log.Error($"Failed to reconnect and send data."); - return false; - } - } + Log.Error($"Failed to reconnect and send data."); + return false; + } } }