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>();
Session["Messages"] = BL.GetMyMessages();
BL.MessageReceived += RefreshUserMessages();
public static void RefreshUserMessages(){
}
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) {
if(MessageReceived != null) {
MessageReceived (userid, msg)
}
}
Any idea? How to implement such ASP.Net
source
share