Static life cycle

B

Brian

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
 
K

Karl Seguin [MVP]

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
 
B

Bruce Barker

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top