SignalR - Checking if a user is still connected

前端 未结 4 812
谎友^
谎友^ 2020-12-09 11:23

I have a hub with method that is called client-side. This method launches a timer with a delegate that runs every 10 seconds. Since it wouldn\'t make sense to keep running t

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 11:57

    From http://forums.asp.net/t/1829432.aspx/1?How+do+I+get+list+of+connected+clients+on+signalr+

    IHubContext context = GlobalHost.ConnectionManager.GetHubContext();
    context.Clients.notify("Hello world");
    

    So you should be able to get context.Clients.Count.

    That post also references the wiki which has lots of good info. You could try using the OnConnected/OnDisconnected examples to track the users, and when you get to zero users stop your call.

提交回复
热议问题