Track connected alarm devices

I need to check if a specific user is all connected.

I have the following HashSet that tracks users:

public static class UserHandler
{
    public static HashSet<string> ConnectedIds = new HashSet<string>();
}

So, disabled:

    public override Task OnDisconnected()
    {
        UserHandler.ConnectedIds.Remove(this.Context.ConnectionId);
        if (UserHandler.ConnectedIds.Count == 0)
        {
               // STOP TASK -> SET CANCELLATION
        }
        return base.OnDisconnected();
    }

and connected:

    public override Task OnConnected()
    {
        Logger.Log.file.Info("[TaskActionStatus HUB => OnConnected] Start");

        UserHandler.ConnectedIds.Add(this.Context.ConnectionId);

        // start task only if at least one listener
        if (UserHandler.ConnectedIds.Count < 2)
        {
            // START A TASK -> (WHILE LOOP THAT GETS DATA FROM DB EVERY 2 SEC)
        }

        return base.OnConnected();
    }

Now the problem arises when users simply close their browser window. I have no way of knowing if it is disabled.

Therefore, based on some question here , I would call each client and get an answer. I do not know how to do that.

I think I would have this:

public static void CheckConnectedUsers()
{
    var context = GlobalHost.ConnectionManager.GetHubContext<TaskActionStatus>();
    foreach (var connection in UserHandler.ConnectedIds)
    {
        context.Clients.Client(connection).verifyConnected("online?");
    }
}

BUT, how do I get a response from a client?

EDIT: steps taken:

, , . , , 2 ( ). ​​: 2 , signalR. HashSet 2 . , /. (, , OnDisconnected, HashSet ConnectionId, , "", OnDisonnected, OnConnected, connectionId HashSet. 1 ConnectionId HashSet , HashSet 2 ( , / ), .

+5
2

SignalR 1.0, OnDisconnected , ( , ).

OnDisconnected , "" , "", , ( , SignalR).

30 OnDisconnected "" . GlobalHost.Configuration.DisconnectTimeout.

+6

. OnDisconnect . , , , .

Public Sub checkconnections()
    For Each s In users
        Clients.User(s).areYouThere()
    Next
    users = New List(Of String)
    System.Threading.Thread.Sleep(5000)
    checkconnections()
End Sub
Public Sub imHere()
    Dim id = GetClientId()
    If Not users.Contains(id) Then
        users.Add(id)
    End If
    Clients.All.sendCount(count)
End Sub

5 , .

"areYouThere", "imHere", .

, .

0

All Articles