I have a web site where many registered users are connected on the same time and they can send messages one to each other. Each user has his own Session object on server and in this Session object I store "Messages" list - this are the User's 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 know when the user received a new message - I don't want on each request to interrogate my database.

I tried to use an event in by BL classes (when a message is stored in database, an event is raised), but the events don't pass from one Session to other 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, in ASP.Net such

Related posts

Recent Viewed