Signalr 当部署到服务器时,信号器事件变得间歇性

Signalr 当部署到服务器时,信号器事件变得间歇性,signalr,Signalr,当通过VS-IISExpress在本地运行时,所有这些都可以100%正常工作 当我发布到一个Web服务器(在网络上或在线上)时,我有一些事件停止触发“OnConnected”。。。但并非总是如此。如果我刷新它,它可能会启动,也可能不会 有问题的事件是ResetTimer,请参见下面的示例代码 我已登录,控制台未显示任何错误 我正在使用信号器1.0.1 <script type="text/javascript"> var timerTime, setIntervalI

当通过VS-IISExpress在本地运行时,所有这些都可以100%正常工作

当我发布到一个Web服务器(在网络上或在线上)时,我有一些事件停止触发“OnConnected”。。。但并非总是如此。如果我刷新它,它可能会启动,也可能不会

有问题的事件是ResetTimer,请参见下面的示例代码

我已登录,控制台未显示任何错误

我正在使用信号器1.0.1

    <script type="text/javascript">
    var timerTime, setIntervalInstance;
    $(function () {
        $('#rollresults').tablesorter({ headers: { 0: { sorter: false }, 1: { sorter: true }, 2: { sorter: false } } });

        $.connection.hub.logging = true;
        // Proxy created on the fly          
        var chat = $.connection.brewBattleHub;
        // Start the connection
        $.connection.hub.qs = 'groupName=@ViewContext.RouteData.Values["groupName"]';
        $.connection.hub.start().done(function () {
            $("#broadcast").click(function () {
                // Call the chat method on the server
                chat.server.roll($("#drinkname").val(), $("#comment").val().substr(0, 40));
                $("#rollresults").show('slow');
                $("#broadcast").prop("disabled", "disabled");
                $("#drinkname").prop("disabled", "disabled");
                $("#comment").prop("disabled", "disabled");
            });

            setIntervalInstance = window.setInterval(timerTick, 1000);
        }).fail(function (reason) {
            console.log("SignalR connection failed: " + reason);
            //chat.server.sendMessage(@Model.UserName + " has Error! (Check logs)");
        });


        // Declare a function on the chat hub so the server can invoke it          
        chat.client.addRoll = function (player, roll, drink, comment) {
            $("#rollresults").find("tr").eq(1).removeClass('loserrow');
            $('#rollresults tbody').append('<tr><td>' + player + '</td>' + '<td>' + roll + '</td>' + '<td>' + drink + '</td>' + '<td>' + comment + '</td></tr>');
            $("#rollresults").trigger("update");
            $("#rollresults").tablesorter({ sortList: [[1, 0]] });
            $("#rollresults").find("tr").eq(1).addClass('loserrow');
        };

        chat.client.addMessage = function (message) {
            $('#messages').append("<div class='message'>" + message + "</div>");
        };

        chat.client.resetTimer = function () {
            timerTime = 30;
        };

        function timerTick() {
            if (timerTime > 0) {
                timerTime = timerTime - 1;
                $('#timer').html("<div>Starting in: " + timerTime + "</div>");
                $("#timerbox").show('slow');
            } else {
                clearInterval(setIntervalInstance);
                $("#broadcast").removeProp("disabled", "disabled");
                $('#timerbox').hide('slow');
            }
        }
    });
控制台

 [09:10:01 GMT+0100 (GMT Daylight Time)] SignalR: Negotiating with '/signalr/negotiate?     groupName=Public'. jquery.signalR-1.0.1.js:54 
[09:10:01 GMT+0100 (GMT Daylight Time)] SignalR: Attempting to connect to SSE endpoint 'http://server:88/signalr/connect?transport=serverSentEvents&connectionToke…onData=%5B%7B%22name%22%3A%22brewbattlehub%22%7D%5D&groupName=Public&tid=4' jquery.signalR-1.0.1.js:54
[09:10:01 GMT+0100 (GMT Daylight Time)] SignalR: EventSource connected jquery.signalR-1.0.1.js:54
[09:10:01 GMT+0100 (GMT Daylight Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332 and a connection lost timeout of 20000 jquery.signalR-1.0.1.js:54
[09:10:01 GMT+0100 (GMT Daylight Time)] SignalR: Triggering client hub event 'addMessage' on hub 'brewBattleHub'. 
补遗
实际上,在本地似乎无法100%工作(大多数情况下),我认为这可能是由于延迟引起的问题?

这不是一个令人满意的解决方案,但在ResetTimer()之前添加线程睡眠似乎已经解决了这一问题

    Groups.Add(Context.ConnectionId, @group.Name);
    Clients.OthersInGroup(@group.Name).addMessage(HttpUtility.HtmlEncode(user.Name + " has connected."));
    Clients.Caller.addMessage(HttpUtility.HtmlEncode("You've connected..."));

    Thread.Sleep(TimeSpan.FromSeconds(1)); //<<<<<<<<<
    ResetTimer(@group.Name);

我不知道你是怎么解决的,但上帝保佑你!这是我的问题:
    Groups.Add(Context.ConnectionId, @group.Name);
    Clients.OthersInGroup(@group.Name).addMessage(HttpUtility.HtmlEncode(user.Name + " has connected."));
    Clients.Caller.addMessage(HttpUtility.HtmlEncode("You've connected..."));

    Thread.Sleep(TimeSpan.FromSeconds(1)); //<<<<<<<<<
    ResetTimer(@group.Name);
    public async override Task OnConnected()
    {
      --->> await Groups.Add(Context.ConnectionId, "TestGroup"); 

            Clients.Group("TestGroup").showBoxOne();
            Clients.Group("TestGroup").showBoxTwo();
            Clients.Group("TestGroup").showBoxThree();
            Clients.Group("TestGroup").showBoxFour();
            Clients.Group("TestGroup").showBoxFive();
        }

        await base.OnConnected();
    }