Thanks Bruce,
That's what I figured. My static constructor doesn't really last an
hour, it's just a hypothetical situation (probably a bad choice of an
example). My static constructor really only should take about a second
or so. I'm simply trying to find out if all requests to the same
static property will wait for the static constructor to finish. This
happens to be very important for my app.
Cowboy, sorry I chose an hour; bad example.
George, I think you missed my point. I know the constructor will
finish before reading the static property. What I'm trying to find out
is if a 2nd (different) request for the same static property comes in
before the static constructor is finished executing from the first
request - what happens then? I would guess that it autamically
"locks" like bruce suggested, but if it didn't I'd have some issues.
Or to rephrase - I don't need to put any locking into my constructor
correct?
Big picture, I've always been a big fan of static methods and static
properties in an ASP.NET. Used correctly, it can really improve speed/
effeciency on high traffic sites. However, using static properties
you have to be carefull for multi-threaded locking issues. These
issues only arrise when you try and read and write to the same
memory. Therefore, I've avoided this by just having static properties
that are "get" only and methods with only local variables. The one
exception is in the static constructor where I "write" to these static
properties. This is what led me to this post.
Thanks!
Dave
On Oct 16, 12:48*pm, bruce barker
<brucebar...@discussions.microsoft.comwrote:
yes. the runtime takes a lock, so no code can access the class statics until
the constructor has completed. of course if it took an hour, asp.net would
try to kill the thread, which would not die until the constructor completed,
so a recycle would probably happen.
-- bruce (sqlwork.com)
"Dave" wrote:
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 makes sense. *If a second (different) request at
11:01 am comes in and tries to read the same property, will it wait
until the static constructor is finished? *I'm hoping it does... If it
doesn't then the 2nd request will read dirty data from un-initialized
properties.
In my scenerio, the static constructor runs much quicker, but it's a
high traffic mission critical financial application that must read the
info each time correctly.
Thanks!
Dave- Hide quoted text -
- Show quoted text -