我正在连接到这样的 signalR 集线器:

    $scope.starthubD = function() {
        $.connection.hub.start().done(function () {
            $.connection.HubName.server.method(sessionId);
        });
    };

我收到这样的消息:
    $.connection.HubName.client.method= function(msg) {
        $scope.cars.push(msg);
    };

通过集线器,我启动了 10-12 个长时间运行的线程:
public class ProcessHub: Hub
{
        IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<ProcessHub>();

        new Thread(() => new Process(connectionId, hubContext)).Start();
        new Thread(() => new Process2(connectionId, hubContext)).Start();
        new Thread(() => new Process3(connectionId, hubContext)).Start();
}

线程本身使用以下命令直接向客户端报告:
hubContext.Clients.Client(connectionId).report(data);

我遇到的问题是它大部分时间都可以工作,但有时我会与此消息断开连接:

最佳答案

我发现了问题所在。其中一个线程抛出异常,导致与集线器的连接丢失。

关于c# - 为什么我的 SignalR 应用有时会断开连接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23194099/

10-14 11:49