How to send event to all sessions in ASP .NET ?

Discussion in 'ASP .Net' started by Borr, Nov 5, 2003.

  1. Borr

    Borr Guest

    Hi,

    I am writing an ASP .NET application that has a following
    logic : if one of application users performs some specific
    action, ALL other users that are browsing some page (lets
    call it "WaitingForSpecificAction.aspx"), should get event
    that this action is performed.

    How to do it ?

    I defined class like this :

    public class EventManager
    {
    public delegate void ActionPerformed(object source,
    EventArgs e);
    public event ActionPerformed OnActionPerformed;

    public void PerformAction()
    {
    ... // Fill EventArgs e variable
    if (OnActionPerformed != null) {
    OnActionPerformed(this, e);
    }
    }
    }

    This class instance is an entry in Application collection
    and can be accessed as Application["EntryName"]. I call
    PerformAction() method from a page where the user can
    perform the action.

    -------
    On "WaitingForSpecificAction.aspx" I subscribe on
    OnActionPerformed event :

    EventManager em = Application["EntryName"] as EntryManager;
    em.OnActionPerformed += new EventManager.ActionPerformed
    (OnActionPerformed);

    and define OnActionPerformed event handler :

    private void OnActionPerformed (object source, GameEvent e)
    {
    ...
    }

    It does not work ! For example, if OnActionPerformed()
    method contains Response.Redirect or Server.Transfer
    calls, it fails. Probably it is because of event is raised
    in one session and handled in another one. But ... HOW TO
    DO IT CORRECTLY ?
     
    Borr, Nov 5, 2003
    #1
    1. Advertising

  2. Borr

    NoOne Guest

    Sorry to say this cannot be done using ASP.NET and events.

    "Borr" <> wrote in message
    news:0c3b01c3a3a4$ea563c70$...
    > Hi,
    >
    > I am writing an ASP .NET application that has a following
    > logic : if one of application users performs some specific
    > action, ALL other users that are browsing some page (lets
    > call it "WaitingForSpecificAction.aspx"), should get event
    > that this action is performed.
    >
    > How to do it ?
    >
    > I defined class like this :
    >
    > public class EventManager
    > {
    > public delegate void ActionPerformed(object source,
    > EventArgs e);
    > public event ActionPerformed OnActionPerformed;
    >
    > public void PerformAction()
    > {
    > ... // Fill EventArgs e variable
    > if (OnActionPerformed != null) {
    > OnActionPerformed(this, e);
    > }
    > }
    > }
    >
    > This class instance is an entry in Application collection
    > and can be accessed as Application["EntryName"]. I call
    > PerformAction() method from a page where the user can
    > perform the action.
    >
    > -------
    > On "WaitingForSpecificAction.aspx" I subscribe on
    > OnActionPerformed event :
    >
    > EventManager em = Application["EntryName"] as EntryManager;
    > em.OnActionPerformed += new EventManager.ActionPerformed
    > (OnActionPerformed);
    >
    > and define OnActionPerformed event handler :
    >
    > private void OnActionPerformed (object source, GameEvent e)
    > {
    > ...
    > }
    >
    > It does not work ! For example, if OnActionPerformed()
    > method contains Response.Redirect or Server.Transfer
    > calls, it fails. Probably it is because of event is raised
    > in one session and handled in another one. But ... HOW TO
    > DO IT CORRECTLY ?
    >
     
    NoOne, Nov 5, 2003
    #2
    1. Advertising

  3. Borr

    charles Guest

    ....But you can do a funky thing by polling an application variable every 10th of a second and setting the applcation variable...

    Something Like:
    public void WaitForAlert()
    {
    int iOldAlertVal = 0;
    if (Application["TheAlert"] != null)
    iOldAlertVal = Application["TheAlert"];
    while (Application["TheAlert"] == iOldAlertVal)
    System.Threading.Thread.Sleep(100);
    }

    public void SendAlert()
    {
    int iOldAlertVal = 0;
    if (Application["TheAlert"] != null)
    iOldAlertVal = Application["TheAlert"];
    Application["TheAlert"] = iOldAlertVal + 1;
    }

    charles
    "Borr" <> wrote in message news:0c3b01c3a3a4$ea563c70$...
    > Hi,
    >
    > I am writing an ASP .NET application that has a following
    > logic : if one of application users performs some specific
    > action, ALL other users that are browsing some page (lets
    > call it "WaitingForSpecificAction.aspx"), should get event
    > that this action is performed.
    >
    > How to do it ?
    >
    > I defined class like this :
    >
    > public class EventManager
    > {
    > public delegate void ActionPerformed(object source,
    > EventArgs e);
    > public event ActionPerformed OnActionPerformed;
    >
    > public void PerformAction()
    > {
    > ... // Fill EventArgs e variable
    > if (OnActionPerformed != null) {
    > OnActionPerformed(this, e);
    > }
    > }
    > }
    >
    > This class instance is an entry in Application collection
    > and can be accessed as Application["EntryName"]. I call
    > PerformAction() method from a page where the user can
    > perform the action.
    >
    > -------
    > On "WaitingForSpecificAction.aspx" I subscribe on
    > OnActionPerformed event :
    >
    > EventManager em = Application["EntryName"] as EntryManager;
    > em.OnActionPerformed += new EventManager.ActionPerformed
    > (OnActionPerformed);
    >
    > and define OnActionPerformed event handler :
    >
    > private void OnActionPerformed (object source, GameEvent e)
    > {
    > ...
    > }
    >
    > It does not work ! For example, if OnActionPerformed()
    > method contains Response.Redirect or Server.Transfer
    > calls, it fails. Probably it is because of event is raised
    > in one session and handled in another one. But ... HOW TO
    > DO IT CORRECTLY ?
    >
     
    charles, Nov 5, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Cox [Microsoft MVP]

    Re: Relationship between IIS Sessions and ASP.NET Sessions?

    Ken Cox [Microsoft MVP], Aug 8, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    5,419
    Luther Miller
    Aug 8, 2003
  2. Andreas Klemt
    Replies:
    1
    Views:
    4,006
    Brock Allen
    Apr 15, 2005
  3. scottymo
    Replies:
    3
    Views:
    766
    Dominick Baier
    Sep 30, 2006
  4. Bookham Measures

    Moving from ASP Sessions to Database Sessions

    Bookham Measures, Jul 23, 2007, in forum: ASP General
    Replies:
    19
    Views:
    601
    Bookham Measures
    Aug 23, 2007
  5. Chris Reay

    Does Socket.send send all bytes?

    Chris Reay, Nov 3, 2003, in forum: Ruby
    Replies:
    2
    Views:
    236
    Chris Reay
    Nov 4, 2003
Loading...

Share This Page