static constructor - when fired in web application?

N

n_o_s_p_a__m

I have a method call in my static constructor which initializes 2
variables. I need to know when the static constructor (after the first
call) will be called. Does unloading the virtual directory and
reloading it call the static constructor again? I have heard that
changing the web.config forces the static constructor to fire again.
Please advise.

-KJ
 
B

Brock Allen

Static constructors are called prior to the first access to that class. Given
this rule, it's possible that it never runs for the lifetime of the application.
This rule is honored per AppDomain, so if your application restarts somehow
(perhaps by updating web,config) then this can be called again. Also, the
static variables are per-AppDomain, so if the same assembly is loaded into
two applications running in the same ASP.NET worker process will have two
copies of those statics loaded in memory -- one per application (IOW, virtual
directory or AppDomain).
 

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

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,225
Latest member
Top Crypto Podcasts

Latest Threads

Top