public async Task SendMessage(BaseMessage message) { _currentMessageId++; message.Id = _currentMessageId; string json = JsonConvert.SerializeObject(message); var taskSource = new TaskCompletionSource<bool>(); _webSocket.SendAsync(json, sent => { if (sent) { taskSource.SetResult(true); } else { taskSource.SetException(new Exception("Error occured while sending message")); } }); await taskSource.Task; }
public Task SendMessage(BaseMessage message) { System.Threading.Interlocked.Increment(ref _currentMessageId); message.Id = _currentMessageId; string json = JsonConvert.SerializeObject(message); var taskSource = new TaskCompletionSource<bool>(); _webSocket.SendAsync(json, sent => { if (sent) { taskSource.SetResult(true); } else { taskSource.TrySetException(new Exception("Error occured while sending message")); } }); return taskSource.Task; }
public Task SendMessage(BaseMessage message) { SendMessage_Message = message; return Task.Factory.StartNew(() => { }); }