Static variable interference

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

My question: I use a few static vars in my site and want to know if their values
interfere between ore than one session.
Sample:
First session: static int x = 10
Second session: static int x = 5
If a third session is started does the value of my static remain its value in all sessions, or is the value the same in all sessions.
I know that this sounds a bit silly but i have problems which look like that is the fault.

Thanks for any answers
 
Harald said:
Hi

My question: I use a few static vars in my site and want to know if their values
interfere between ore than one session.
Sample:
First session: static int x = 10
Second session: static int x = 5
If a third session is started does the value of my static remain its value in all sessions, or is the value the same in all sessions.
I know that this sounds a bit silly but i have problems which look like that is the fault.

Thanks for any answers

A static member is global (HttpApplication) in scope, not limited to a specific (http-)session.
If you want session-specific values, you should use Session.

store:
Session["x"] = 5;

retrieve:
int x = 0;
if (Session["x"] != null) x = (int)Session["x"];


Hans Kesting
 
Back
Top