ASP.Net Intersessional Event

I have a website where many registered users are connected at the same time and they can send messages to each other. Each user has his own Session object on the server, and in this Session object I store a list of "Messages" - these are user messages.

Session["Messages"] = new List<UserMesages>();
//.... more code here
Session["Messages"] = BL.GetMyMessages();  //get a list of messages
//.... more code here
BL.MessageReceived += RefreshUserMessages();

public static void RefreshUserMessages(){
    //this code doesn't execute for all the sessions, but only for my current user.
}

I need a way to find out when a user received a new message - I do not want every request to query my database.

I tried to use the event in the BL classes (when the message is stored in the database, an event occurs), but the events do not pass from one session to another session.

In my BL class, I have:

public delegate void MessageReceivedEventHandler(object sender, MessageEventArgs e);
public static event MessageReceivedEventHandler MessageReceived;

public static int SaveMessageForUser(Message msg) {
    //... save the message
    if(MessageReceived != null) {
        MessageReceived (userid, msg)  // <-- correct parameters go here
    }
}

Any idea? How to implement such ASP.Net

+4
source share
2

, , - - , , , , , . , .

+1

Source: https://habr.com/ru/post/1622542/


All Articles