我正在使用 SignalR。对话完成后,我尝试在对话中添加所有收件人并通知在线收件人。
所有代码都很好,但它只通知第一个收件人。所以我想广播只是第一次等待
public void NotifyConversation(ConversationModel model, string name)
{
var groupId = model.ID.ToString();
var recipients = model.Recipients;
var allconnections = new List<string>();
foreach (var recipient in recipients)
{
var connections = _manager.GetConnections(recipient.Name).Where(x => x != null);
allconnections.AddRange(connections);
}
var tasks = allconnections
.Select(connection =>
Task.Run(() => { Context.Groups.Add(connection, groupId); })).ToArray();
Task.WaitAll(tasks);
Context.Clients.Group(groupId).broadcastConversation(model);
}