SignalR event becomes intermittent when deployed to a server

后端 未结 1 1005
盖世英雄少女心
盖世英雄少女心 2021-01-20 11:42

When running locally through VS - IIS Express it all works fine 100%.

When i then publish to a webserver (on network or online) I have some event stop firing for \"O

相关标签:
1条回答
  • 2021-01-20 11:44

    Not a satisfying fix but adding a thread sleep before ResetTimer() seems to have fixed it.

        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);
    

    Addendum

    Even even better fix, issue is Groups.Add is ASYNCHRONOUS!! awaiting it solves the issue also. (dont forget to make OnConnected async too)

        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();
        }
    
    0 讨论(0)
提交回复
热议问题