473,383 Members | 1,892 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,383 software developers and data experts.

Static life cycle

How static are static variables in ASP.NET?

This is not a real example, but it's good enough to make the point. Say I
have a custom control with a dictionary. The dictionary is composed of
10,000 strings read from a file and hashed. Obviously I don't want/need to
rebuild the data structure for each page render.

If it were a traditional application, I would use a static constructor and
hashtable. Can I expect this to work in IIS?

I ask because .net seems to rebuild projects on key file changes (like
global.asax). Does this feature destroy the usefullness of static
variables?

Thanks,
Brian

Feb 27 '06 #1
2 2001
static variables are very static - they are shared for all requests
throughout the lifetime of the application (or until an app domain restart).
This is different than the behaviour you'd see in php.

They aren't thread-safe...so you should only write to them in controlled
settings.

Generally, the HttpCache is used for what you are talking about.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Brian" <br***@nospam.com> wrote in message
news:T5****************@tornado.socal.rr.com...
How static are static variables in ASP.NET?

This is not a real example, but it's good enough to make the point. Say I
have a custom control with a dictionary. The dictionary is composed of
10,000 strings read from a file and hashed. Obviously I don't want/need
to rebuild the data structure for each page render.

If it were a traditional application, I would use a static constructor and
hashtable. Can I expect this to work in IIS?

I ask because .net seems to rebuild projects on key file changes (like
global.asax). Does this feature destroy the usefullness of static
variables?

Thanks,
Brian

Feb 27 '06 #2
static have the same life cycle as the appdomain they are contained in. in
asp.net trems that means they live until a recycle (file change, inactivity
timeout, etc).

-- bruce (sqlwork.com)

"Brian" <br***@nospam.com> wrote in message
news:T5****************@tornado.socal.rr.com...
How static are static variables in ASP.NET?

This is not a real example, but it's good enough to make the point. Say I
have a custom control with a dictionary. The dictionary is composed of
10,000 strings read from a file and hashed. Obviously I don't want/need
to rebuild the data structure for each page render.

If it were a traditional application, I would use a static constructor and
hashtable. Can I expect this to work in IIS?

I ask because .net seems to rebuild projects on key file changes (like
global.asax). Does this feature destroy the usefullness of static
variables?

Thanks,
Brian

Feb 27 '06 #3

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

Similar topics

5
by: LinuxGuy | last post by:
Hi, I have come across singleton class with some member variables are declared as static with public scope. As singleton class always return only one instance. ie. single copy of object is ...
1
by: athos | last post by:
Hi all, Believe you have sound experience in development, however, if we look at the whole Software Development Life Cycle (SDLC) of the project, say, 1. Project Initiation, 2. Gathering...
6
by: jim | last post by:
Hi All, I like to know the life cycle of an ASP .NET Application( incudieng server application, such as .NET Web Service). That means from initialization to fully running and how to reboot it or...
6
by: devg | last post by:
I want to have a global variable in my app so I can change my DB connect string for all the pages based on the person's login information. I have a class that has a static string. I can get/set...
16
by: bharathi.vempati | last post by:
hi Can any one explain me the life cycle of C from source code to process termination. please make it fast k bye -ramya
1
by: =?Utf-8?B?U2FtZWVrc2hh?= | last post by:
I vaguely know that HTTP Post does not send all the data (hidden fields?) along with the request. I would like to know the stage in ASP.Net application life cycle where the POST data is read - is...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
20
by: Nickolai Leschov | last post by:
Hello all, I am programming an embedded controller that has a 'C' library for using its system functions (I/O, timers, all the specific devices). The supplied library has .LIB and .H files. ...
4
by: lander | last post by:
I've read the page life cycle thing in msdn, still, i'm getting a bit confused of thinking how all the things are going under the hood... I know that when page loading, that the controls'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.