private async Task SendMessage() { try { do { if (WebSocket.State != WebSocketState.Open) { // Make this a faulted task and trigger the OnError even to maintain consistency with the HttpBasedTransports var ex = new InvalidOperationException("Error_DataCannotBeSentDuringWebSocketReconnect"); Connection.OnError(ex); return; } var message = ""; QueueOfSends.TryDequeue(out message); if (string.IsNullOrEmpty(message) && !CanSendMessage(message)) { return; } var byteMessage = Encoding.UTF8.GetBytes(message); var segmnet = new ArraySegment <byte>(byteMessage); await WebSocket.SendAsync(segmnet, WebSocketMessageType.Text, true, DisconectToken); } while (QueueOfSends.Count > 0); } catch (Exception ex) { var men = ex.Message; } }
public Task SendMessageAsync(string message) { QueueOfSends.Enqueue(message); return(Task.FromResult(0)); }