Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to send event to all sessions in ASP .NET ?

Reply
Thread Tools

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

 
 
Borr
Guest
Posts: n/a
 
      11-05-2003
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 ?

 
Reply With Quote
 
 
 
 
NoOne
Guest
Posts: n/a
 
      11-05-2003
Sorry to say this cannot be done using ASP.NET and events.

"Borr" <(E-Mail Removed)> wrote in message
news:0c3b01c3a3a4$ea563c70$(E-Mail Removed)...
> 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 ?
>



 
Reply With Quote
 
 
 
 
charles
Guest
Posts: n/a
 
      11-05-2003
....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" <(E-Mail Removed)> wrote in message news:0c3b01c3a3a4$ea563c70$(E-Mail Removed)...
> 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 ?
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving from ASP Sessions to Database Sessions Bookham Measures ASP General 19 08-23-2007 03:51 PM
Cookieless Sessions (Sessions Without Cookies) and Security scottymo ASP .Net Security 3 09-29-2006 11:00 PM
How to kill all sessions when working with ASP.NET Session State Service? Andreas Klemt ASP .Net 1 04-15-2005 02:45 PM
Does Socket.send send all bytes? Chris Reay Ruby 2 11-04-2003 08:22 PM
Re: Relationship between IIS Sessions and ASP.NET Sessions? Ken Cox [Microsoft MVP] ASP .Net 1 08-08-2003 03:22 PM



Advertisments