SignalR - Checking if a user is still connected

前端 未结 4 827
谎友^
谎友^ 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:50

    If you save your connectionId in your database, you can check this:

    var heartBeat = GlobalHost.DependencyResolver.Resolve();
    
    var connectionAlive = heartBeat.GetConnections().FirstOrDefault(c=>c.ConnectionId == connection.ConnectionId);
    
    if (connectionAlive.IsAlive)
    {
    //Do whatever...
    }
    

提交回复
热议问题