472,790 Members | 3,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,790 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 2425
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.