473,657 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Static constructor processing

Will object instantiation of an object not occur until the static
constructor has run? In other words, if I have logic in a static
constructor that takes, lets say 5 seconds. Will all other attempts to
create an object of that type be "blocked" for that 5 secs until the static
constructor processing has occurred?

Nov 16 '05 #1
3 2004
Kevin C <kc@noneya.co m> wrote:
Will object instantiation of an object not occur until the static
constructor has run? In other words, if I have logic in a static
constructor that takes, lets say 5 seconds. Will all other attempts to
create an object of that type be "blocked" for that 5 secs until the static
constructor processing has occurred?


Yes, they will.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
> Will object instantiation of an object not occur until the static
constructor has run? In other words, if I have logic in a static
constructor that takes, lets say 5 seconds. Will all other attempts to
create an object of that type be "blocked" for that 5 secs until the static constructor processing has occurred?

If you explicitlx provide a static ctor the type is not marked with
beforefieldinit which means that it is guaranteed that the static ctor run
exactly at the moment before you access the first time a field of this class
or create an instance. You can also rely on that behaviour in a
multithreaded program.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 16 '05 #3
Perfect thanks!!

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Kevin C <kc@noneya.co m> wrote:
Will object instantiation of an object not occur until the static
constructor has run? In other words, if I have logic in a static
constructor that takes, lets say 5 seconds. Will all other attempts to
create an object of that type be "blocked" for that 5 secs until the static constructor processing has occurred?


Yes, they will.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4

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

Similar topics

3
18807
by: Amit | last post by:
is there anything like static constructors or destructors in C++ ? if yes, how to implement it? Thanks, Amit.
10
2761
by: Grahamo | last post by:
Hi, I have a a routine that is frequently called. It simply iterates over a list of dates and does some sanity checking. The following pseudo code summarises it. void check() { const Date someDate = 1/1/2005;
3
339
by: Kevin C | last post by:
Will object instantiation of an object not occur until the static constructor has run? In other words, if I have logic in a static constructor that takes, lets say 5 seconds. Will all other attempts to create an object of that type be "blocked" for that 5 secs until the static constructor processing has occurred?
1
1683
by: Ray Ackley | last post by:
I'm experiencing a threading problem that's really perplexing me. I have a multithreaded application that reads car ECU information that's sent over the serial port by the ECU and received by the laptop/program. I'll try to give a concise synopsis as the program is easily 10k+ lines. main.cs - contains the application start function. Here's the entire code (minus misc junk) as it's rather small -
5
6269
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
3818
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 ways to do this through prototyping and other techniques, but these behaviors need to be static and...
12
3429
by: Hemanth | last post by:
Hi, I have a base class with a static constructor and some abstract methods. Derived classes implement these methods. From articles on the web, it appears that there is no guarentee that this static constructor of the base class would be invoked even if a an object of the derived class is created. Is this correct ? Is there any way to ensure the base class's static constructor is invoked before the derived class instance is constructed ?...
10
1752
by: John A Grandy | last post by:
Say I have Class1 which contains static Class2 var1 = new Class2(); Is Class2 constructor code only executed if var1 is referenced in the code-execution path ? Or is Class2 constructor code executed on load of any class that references Class1 ?
4
3102
by: mnowosad | last post by:
As far I know, static variables are tied to AppDomain scopes. So, every time an executing code within an AppDomain references a class for the the first time since the AppDomain was created/loaded, the .NET executes the assignments done in the class static variables declarations and runs the static constructor of that class. So, I expected that, as in ASP.NET web site, for a given Web Service site, the AppDomain would be initialized upon...
4
3149
by: BLUE | last post by:
VS .NET 2003 CF In this method I cannot catch exceptions thrown by Settings constructor (for example FileNotFoundException) but only an OutOfMemory exception due to Get returning void. Why??? private void GtmForm_Load(object sender, System.EventArgs e) {
0
8425
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8845
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
5647
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.