473,406 Members | 2,549 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,406 software developers and data experts.

static constructor - when fired in web application?

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

Nov 19 '05 #1
1 1759
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).

-Brock
DevelopMentor
http://staff.develop.com/ballen
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


Nov 19 '05 #2

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

Similar topics

7
by: Sunny | last post by:
Hi all, According C# Language Specification : 10.11 Static constructors: The static constructor for a class executes at most once in a given application domain. The execution of a static...
5
by: A.M | last post by:
Hi, I have i utility class contains static functions (and also members) I usually use in may applications. Can i have a static like constructor so any time the app starts, The constructor...
3
by: Kirk Marple | last post by:
Just want to see if this is 'by design' or a bug... I have a common List<T> defined in a base class, and the base class has a static property to expose this list. I wanted the derived class to...
5
by: | last post by:
Hi, How long do webservice objects live for? In particular, if i have static variables filled with data from a static constructor in a webservice, how long will that data persist? thxs
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: Marty | last post by:
Hi, I have a class that I modified to be static. It is now a public sealed class and all function are static, no more constructor but a init() function to do the constructor job. This class...
1
by: ThazKool | last post by:
I would like to attach an event handler to the application start without having to use a Global.asax file. If this could be done from a static constructor then that would be ideal. I guess...
6
by: =?Utf-8?B?TWF0dA==?= | last post by:
I'm having a problem with a static class constructor being called twice. I have the static class MasterTaskList which uses a BackgroundWorker to execute multiple methods on a separate thread. The...
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: 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...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.