private async void SendMessage() { if (String.IsNullOrEmpty(MessageText)) { return; } _uiDispatcher.Invoke(() => { IsMessagingAllowed = false; IsSendingMessage = true; }); var message = new Message { Content = (string)MessageText.Clone(), Receiver = _selectedUser.Username, TimeStamp = DateTime.Now, Sender = _username }; //TODO: should we use this message or wait it from server? var sendMessageTask = _connectionManager.SendMessageAsync(message); await sendMessageTask; if (sendMessageTask.Result.IsSucessful) { lock (_messageLock) { _allMessages[message.Receiver].Add(message); } MessageText = String.Empty; } ; _uiDispatcher.Invoke(() => { IsSendingMessage = false; IsMessagingAllowed = true; }); }