Can static varible cross session

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I define a static variable, like myClass.aString.
If one user in a session update the value of myClass.aString.
Can the other users in other sessions can see this change?
 
hmmm... my first instinct was to reply that a static member is actually
instantiated for each session, since each session is sort-of like its
own application.

Then I realized I wasn't clear on this topic and tried to find an
answer.

Failed to do so, but found an example of how you can avoid problems by
wrapping your access to static members in a lock statement.
See here: http://www.developerfusion.com/show/3821/5/

and, now that you put the bug in my ear, I'll have to find out what's
the real scope of a static member, so maybe I'll post again when I'll
find a better answer.

F.O.R.
 
Olorin said:
hmmm... my first instinct was to reply that a static member is actually
instantiated for each session, since each session is sort-of like its
own application.

Then I realized I wasn't clear on this topic and tried to find an
answer.

Failed to do so, but found an example of how you can avoid problems by
wrapping your access to static members in a lock statement.
See here: http://www.developerfusion.com/show/3821/5/

and, now that you put the bug in my ear, I'll have to find out what's
the real scope of a static member, so maybe I'll post again when I'll
find a better answer.

The real scope of a static member is AppDomain. For ASP.NET, all
requests are likely to execute in the same AppDomain, so different
users all effectively share the same set of static variables.
 
Hi,

It will, static are bound to the app, each request works as a thread of the
app.

cheers,
 
Back
Top