gpt4 book ai didi

c# - 关闭 websocket 时出现 SignalR 错误 - 无效句柄

转载 作者:太空狗 更新时间:2023-10-29 21:57:57 24 4
gpt4 key购买 nike

出现此 SignalR 问题:

Error while closing the websocket: System.Net.WebSockets.WebSocketException (0x80070006): The handle is invalid

我认为问题与这段代码有关:

var currentHub = GlobalHost.ConnectionManager.GetHubContext<HubManager>();
currentHub.Groups.Remove(userConnectionId, roomName);

如何修复?

最佳答案

我遇到了同样的问题,当我向 signalR 添加 SQL 背板时,这种情况就开始了,

它与中心上下文的“新鲜度”有关,我所做的是:

    /// <summary>
/// In case a backplane is used (in case of load balancer) , the instance should always be taken fresh
/// if no backplane is used no need to refresh the instance on each invocation
public class HubContextService
{
bool BackplaneUsed { get; set; }
IHubContext _context = null;

public HubContextService(bool isBackPlaneUsed = true)
{
BackplaneUsed = isBackPlaneUsed;
}

public IHubContext HubContext
{
get
{
if (BackplaneUsed)
{
return GlobalHost.ConnectionManager.GetHubContext<HubManager>();
}
else
{
if (_context == null)
{
_context = GlobalHost.ConnectionManager.GetHubContext<HubManager>();
}
return _context;
}
}
set
{
_context = value;
}
}
}

关于c# - 关闭 websocket 时出现 SignalR 错误 - 无效句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21464685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com