473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Static properties

Hi

I have an ASP app which references a few static properties in some of the
classes. I understand that you should use Session variables, but is it
"possible" to have each session "not" reference the same static members.

For example if I update the static member on one session this change will be
reflected on somebody elses session, which I don't want.

I hope there's an easy solution for this as changing to session variables
may prove to be a pain.

Thanks
Kev
Nov 19 '05 #1
4 2460
No. You could use instance properties instead, but then you'd have to carry
around the instance in the session for it to persist from request to
request. You'll likely need to explain your needs in more detail in order
to get any useful help..specifically with respect to why you can't use
sessions and what you are trying to do..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:d1**********@newsfeed.th.ifl.net...
Hi

I have an ASP app which references a few static properties in some of the
classes. I understand that you should use Session variables, but is it
"possible" to have each session "not" reference the same static members.

For example if I update the static member on one session this change will be reflected on somebody elses session, which I don't want.

I hope there's an easy solution for this as changing to session variables
may prove to be a pain.

Thanks
Kev

Nov 19 '05 #2

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Or**************@TK2MSFTNGP09.phx.gbl...
No. You could use instance properties instead, but then you'd have to
carry
around the instance in the session for it to persist from request to
request. You'll likely need to explain your needs in more detail in order
to get any useful help..specifically with respect to why you can't use
sessions and what you are trying to do..
No is all I needed to know, the reason I asked is because the ASP.Net is
using a framework we developed for use on a windows forms client, obviously
if you fire up the app more than once you get a clean slate, but with
ASP.Net it is session-based.

So rather than relying on the static member used by the framework, I'll need
to adjust to Session variables.

Thanks
Kev

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:d1**********@newsfeed.th.ifl.net...
Hi

I have an ASP app which references a few static properties in some of the
classes. I understand that you should use Session variables, but is it
"possible" to have each session "not" reference the same static members.

For example if I update the static member on one session this change will

be
reflected on somebody elses session, which I don't want.

I hope there's an easy solution for this as changing to session variables
may prove to be a pain.

Thanks
Kev


Nov 19 '05 #3
> I have an ASP app which references a few static properties in some of the
classes. I understand that you should use Session variables,
Actually, the problem is that you DON'T understand. A blanket statement like
"you should use Session variables" indicates that you don't understand, but
have heard people say this. Session variables, Static properties and
methods, and other means of storing data in a more or less global fashion
are tools. A good carpenter understand his tools; otherwise he can't use
them properly.

So, let me see if I can help you understand your tools better.

Anything that is static is stored in the heap, rather than the stack. There
are 2 basic memory areas in any applicaiton. The heap is where all the code
for the app is initially loaded. The stack is where instances (copies) of
variables, functions, etc. are kept when they are instantiated. Data in the
stack is volatile; When it goes out of scope, it is removed from the stack.
When you call a function, for example, a copy (instance) of that function is
placed on the stack. When the function exits, it is pulled off the stack.
The heap, on the other hand, is not volatile. It remains in memory for the
lifetime of the app.

Session is an object, or rather, an instance of an object. It is a managed
memory space (Collection) that you can use in a thread-safe manner. Static
data is in the heap, and there is only one instance of it (hence the term
"singleton"). For this reason, it is not thread-safe. It is entirely
possible for more than one thread to be accessing the data at the same time.

Static data is NOT stored in Session. Session is on the Stack; static data
is in the heap. If yoiu PUT a static member into Session, it still remains
in the heap, and the Session variable points to it.

In addition, static data is by nature global to the entire app. Session data
is only global to a single user Session.

And BTW, you also have the Application Cache to store global data in. The
Application Cache is similar to Session, but global to the entire app, and
it is thread-safe. You also have ViewState, which is scoped to a Page.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Mantorok" <no**@tiscali.co.uk> wrote in message
news:d1**********@newsfeed.th.ifl.net... Hi

I have an ASP app which references a few static properties in some of the
classes. I understand that you should use Session variables, but is it
"possible" to have each session "not" reference the same static members.

For example if I update the static member on one session this change will
be reflected on somebody elses session, which I don't want.

I hope there's an easy solution for this as changing to session variables
may prove to be a pain.

Thanks
Kev

Nov 19 '05 #4
Static members are also not thread-safe..which is dangerous in ASP.Net.

What I've seen most people do is use a smart provider.
public interface IStateInformation
void Add(object key, object value);
void Remove(object key);
...
end interface
interneal class WebState : IStateInformation
public void Add(object key, object value){
HttpContext.Current.Session.Add(key, value);
}
public void Remove(object key){
HttpContext.Current.Session.Remove(key);
}
}

internal class WindowsState : IStateInformation
private static Hashtable _state = new Hashtable;
public void Add(object key, object value){
WindowsState._state.Add(key, value);
}
public void Remove(object key){
WindowsState._state.Remove(key);
}
}
public class StateProvider{
public statc IStateInformation GetProvider{
get {
return (HttpContext.Current != null) ? new WebState() : new
WindowsState();
}
}
}

Anyways, I have no doubt my implementation is bogus..but hopefully it gets
you off in the right direction....I think my WindowState is really
screwed...I'm stuffy..can't tthink...

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:d1**********@newsfeed.th.ifl.net...

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Or**************@TK2MSFTNGP09.phx.gbl...
No. You could use instance properties instead, but then you'd have to
carry
around the instance in the session for it to persist from request to
request. You'll likely need to explain your needs in more detail in order to get any useful help..specifically with respect to why you can't use
sessions and what you are trying to do..
No is all I needed to know, the reason I asked is because the ASP.Net is
using a framework we developed for use on a windows forms client,

obviously if you fire up the app more than once you get a clean slate, but with
ASP.Net it is session-based.

So rather than relying on the static member used by the framework, I'll need to adjust to Session variables.

Thanks
Kev

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Mantorok" <no**@tiscali.co.uk> wrote in message
news:d1**********@newsfeed.th.ifl.net...
Hi

I have an ASP app which references a few static properties in some of the classes. I understand that you should use Session variables, but is it
"possible" to have each session "not" reference the same static members.
For example if I update the static member on one session this change will
be
reflected on somebody elses session, which I don't want.

I hope there's an easy solution for this as changing to session

variables may prove to be a pain.

Thanks
Kev



Nov 19 '05 #5

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

Similar topics

12
by: Sergey Klementiev | last post by:
Why it's impossible to have a static indexer in C#?
3
by: boxim | last post by:
got some static props in some classes some of the props need to refer to other static members of the other classes however, cos they're not simple types, cant use const, have to use readonly how...
7
by: Mike P | last post by:
I have a class with a dozen+ properties, some of which will be set a value, and some not, depending on the constructor called. I also have a method which has only one overload and all of the...
25
by: Sahil Malik [MVP] | last post by:
So here's a rather simple question. Say in an ASP.NET application, I wish to share common constants as static variables in global.asax (I know there's web.config bla bla .. but lets just say I...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
6
by: RSH | last post by:
I'm having a bit of trouble understanding Static properties. I have two forms and I need to be able to access a property from from1 in form2. The code below does not work but I'm not sure why...
8
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it....
2
by: peridian | last post by:
Hello, I should have made a note of which version of php 5 I am currently using, but I didn't (I'm pretty sure it's 5.2.2). Ayway, I just want to clarify that my understanding of the static...
5
by: Dave | last post by:
Hello, Suppose you have a class with a static property with only a get (read only). You also have code in a static constructor that sets these properties but takes 1 hour to run. Now suppose...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.