472,348 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 software developers and data experts.

Scope of Static Members Across Sessions

I am using C# to program ASP.NET. I am using class of static fields to hold
all variables that are common to the application, and I am sure that this is
fine. However, I was also using some static fields to hold values that
calculated every time a user opens a page (unique to each session). These
static fields are used in other classes thoughout the application. However,
it suddenlly struck me that these static fields are (i think) common across
all user sessions so that they may confict when two(or more) users try to
open a page that sets and accesses these fields at the same time. Is that
correct?

I am thinking that I should be using instance field variables for all
variables where the data is unique to that session? Is that correct?

Thanks for the help

Earl
Nov 15 '05 #1
2 5588
Yes, they're common across the application. (not Session)

I've just done exactly the same thing

got a class with static members that are used in classes not derived from
Web.UI.Page
also contain Session specific stuff in instance variables

i.e.

class mystateclass {

protected string _username;

public static string DatabaseServer {
get {
// gets from config file
}
}

public string CurrentUsername {
get {
return _username;
}
}

///////

// in Session_Start

Session["stateinfo"] = new mystateclass();
HTH
sam

"Earl Teigrob" <ea******@hotmail.com> wrote in message
news:Oq****************@tk2msftngp13.phx.gbl...
I am using C# to program ASP.NET. I am using class of static fields to hold all variables that are common to the application, and I am sure that this is fine. However, I was also using some static fields to hold values that
calculated every time a user opens a page (unique to each session). These
static fields are used in other classes thoughout the application. However, it suddenlly struck me that these static fields are (i think) common across all user sessions so that they may confict when two(or more) users try to
open a page that sets and accesses these fields at the same time. Is that
correct?

I am thinking that I should be using instance field variables for all
variables where the data is unique to that session? Is that correct?

Thanks for the help

Earl

Nov 15 '05 #2
Actually, the static variables don't apply to the application, they
apply to the whole app-domain, which the Application is just a part of.
Each web app on IIS runs in its own application domain. Granted, there is
only one Application object per web app, but it is an important distinction,
because static variables are tied to one, and not the other.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"boxim" <sa*********@yahoo.co.uk> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Yes, they're common across the application. (not Session)

I've just done exactly the same thing

got a class with static members that are used in classes not derived from
Web.UI.Page
also contain Session specific stuff in instance variables

i.e.

class mystateclass {

protected string _username;

public static string DatabaseServer {
get {
// gets from config file
}
}

public string CurrentUsername {
get {
return _username;
}
}

///////

// in Session_Start

Session["stateinfo"] = new mystateclass();
HTH
sam

"Earl Teigrob" <ea******@hotmail.com> wrote in message
news:Oq****************@tk2msftngp13.phx.gbl...
I am using C# to program ASP.NET. I am using class of static fields to hold
all variables that are common to the application, and I am sure that this is
fine. However, I was also using some static fields to hold values that
calculated every time a user opens a page (unique to each session).

These static fields are used in other classes thoughout the application.

However,
it suddenlly struck me that these static fields are (i think) common

across
all user sessions so that they may confict when two(or more) users try to open a page that sets and accesses these fields at the same time. Is that correct?

I am thinking that I should be using instance field variables for all
variables where the data is unique to that session? Is that correct?

Thanks for the help

Earl


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve Holdoway | last post by:
Hi there, Is there any way of defining a variable who lives as long as the browser stays active? I did some initial tests, and found that the...
3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I...
4
by: Gery D. Dorazio | last post by:
Gurus, If a static variable is defined in a class what is the scope of the variable resolved to for it to remain 'static'? For instance, lets say...
0
by: Tony Wong | last post by:
I am trying to implement the Singleton Pattern for a assembly (class) which control a common resource on my computer. I need the Singleton behavior...
3
by: mark.norgate | last post by:
Hello I'm writing an application in ASP.NET 1.1 and have come across a problem using static fields in my page classes. I have lots of controls...
2
by: xzzy | last post by:
Using ASP.net, C# and a static class, does the following from MSDN mean: 1. a static hashtable would only live during the session and end when...
5
by: Steven Nagy | last post by:
Hi, I ran a simple test today. I created a web app that calls a static variable which self increments. I then accessed the same app from another...
3
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... At least by the group title, this seems like a question for dotnet.framework.aspnet.caching but that group seems pretty slow. I'm trying...
1
by: Giacomo Catenazzi | last post by:
Hello, To learn the details of C, I've build the following example, could you check if it is correct and if it miss some important cases? Are...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.