C# – Getting a List of Users Currently Using an Application

c

What I need to do :

I've been asked to add a feature to one of our application that would allow a supervisor to send a message to all or one of the users currently using the application.

The application is a winform application using c# and ef6 with a mysql database and is using a RabbitMQ server for different purposes.

My question :

How can I get or maintain a list of users who are currently using the application?

Solution 1:

Log in a database who is currently using the application.

We have done that in the past for another application, but it was unreliable because if the user kill the application or lose a connection to the database, it won't write to the database if he log off.

Solution 2:

I could use the RabbitMQ server. Every user would send a "presence" message every x seconds to tell the other users they are still logged in. Everytime the application would receive such a message, it would add the user to a list or just update the list if the user is already in the list.. If a user would not send a "presence" message after x seconds, he would be considered as logged off.

Am I overthinking this? Is there a better way to implement such a thing?

Edit : i'm trying to avoid having a central server that would maintain the list of user.

Best Answer

The most feasible solution is some variation of Websockets. Luckily, C# supports it. When a user starts the application, a connection between him and a server is created indicating the application runs. When the application is terminated (properly or killed), the process ends and so does the connection.

There's a catch, though. Your current architecture, from what I understand, does not support it. You will need a server which can process WebSocket connections to serve as a listener and manager of your active users. Through this server you may dispatch events to them (WebSockets are bidirectional, meaning it supports both client->server and server->client communication).

Update: I'm no C# programmer, but there seems to be also SignalR. You may want to check that as well.