wyt*_*tes 6 c# exception websocket signalr
我正在研究SignalR项目,有时我遇到这个问题
关闭websocket时出错:System.Net.WebSockets.WebSocketException(0x80070006):句柄无效
我认为问题与我的代码的这一部分有关:
var currentHub = GlobalHost.ConnectionManager.GetHubContext<HubManager>();
currentHub.Groups.Remove(userConnectionId, roomName);
Run Code Online (Sandbox Code Playgroud)
你对这个问题有什么想法,我该怎么办呢?
谢谢
我遇到了同样的问题,当我向 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;
}
}
}
Run Code Online (Sandbox Code Playgroud)