public async void SendNewMessageNoticeToChatUsersAsync(MessageDto newMessage, ClientConnection connection, bool sendPush = true) { try { List <ChatUserVm> chatUsers = await loadChatsService.GetChatUsersAsync(newMessage.ConversationId, null).ConfigureAwait(false); if (sendPush) { pushNotificationsService.SendMessageNotificationAsync( newMessage, chatUsers.Select(opt => new NotificationUser(opt.UserId, opt.IsMuted.Value)).ToList()); } List <Task> noticeTasks = new List <Task>(); foreach (var chatUser in chatUsers) { var clientConnections = connectionsService.GetUserClientConnections(chatUser.UserId); if (clientConnections != null) { noticeTasks.Add(Task.Run(async() => { NewMessageNotice notice = new NewMessageNotice( MessageConverter.GetMessageVm(newMessage, chatUser.UserId), MarkdownHelper.ContainsMarkdownUserCalling(newMessage.Text, chatUser.UserId)); await SendNoticeToClientsAsync(clientConnections.Where(clientConnection => clientConnection != connection), notice).ConfigureAwait(false); })); } } await Task.WhenAll(noticeTasks).ConfigureAwait(false); } catch (Exception ex) { Logger.WriteLog(ex); } }