PC Review


Reply
Thread Tools Rate Thread

Can static varible cross session

 
 
ad
Guest
Posts: n/a
 
      18th Mar 2005
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?


 
Reply With Quote
 
 
 
 
Olorin
Guest
Posts: n/a
 
      18th Mar 2005
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.

 
Reply With Quote
 
VJ
Guest
Posts: n/a
 
      18th Mar 2005
can you give a sample... ??

"ad" <(E-Mail Removed)> wrote in message
news:%23gDS4$(E-Mail Removed)...
>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?
>
>



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      18th Mar 2005
Olorin <(E-Mail Removed)> wrote:
> 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.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      18th Mar 2005
Hi,

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

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"ad" <(E-Mail Removed)> wrote in message
news:%23gDS4$(E-Mail Removed)...
>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?
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
static vs session rodchar Microsoft C# .NET 2 24th Aug 2009 09:02 PM
cross session issue =?Utf-8?B?cHJhc2g=?= Microsoft ASP .NET 0 29th Nov 2006 12:41 AM
Cross Session Error? Session state and kernel-mode output caching don't mix jason Microsoft ASP .NET 0 30th Aug 2006 06:09 AM
Static and Session variables Varangian Microsoft ASP .NET 0 27th Mar 2006 12:21 PM
Can static varible cross session ad Microsoft ASP .NET 3 18th Mar 2005 01:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:11 AM.