public async Task SendMessage(CodeMessage message) { if (client.Connected) { string json = message.Serialize(); byte[] buffer = Encoding.UTF8.GetBytes(json); await messageSemaphore.WaitAsync(); await networkStream.WriteAsync(buffer, 0, buffer.Length); await Task.Delay(buffer.Length * 2 + 100); messageSemaphore.Release(); } else { Disconnected?.Invoke(this, EventArgs.Empty); } }
public async Task SendMessage(CodeMessage message) { Debug.WriteLine(message.Serialize()); await Task.Delay(100); }