473,569 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1774
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
1869
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 constructor is triggered by the first of the following events to occur within an application domain: - An instance of the class is created.
5
5531
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 initializes static class members ? Thanks, Ali
3
11817
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 add items to this list, but have the base class hold the data and expose the property. Problem is, however, that the derived class' static...
5
6262
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
3810
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 experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of...
6
2702
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 inherit from a QuickFix.Application class. I have this object: private static SocketInitiator qfxInitiator; When instantiated, its constructor...
1
1398
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 HttpContext.Current would be used. Also, I would like to attach an event to the first request and then remove it. Does anyone have any thoughts on how...
6
7243
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 static constructor calls a reset function which creates a new instance of BackgroundWorker and attaches the appropriate event handlers. There is also...
5
4452
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 the first request comes in at 11:00 am and tries to read from this property. It will need to wait an hour until the page loads which is fine and...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.