M
Michael Nemtsev
Hello Morgan,
See Jon's explanations there http://www.yoda.arachsys.com/csharp/beforefieldinit.html
MC> In the book *Programming C#* 4th editionby Jesse Liberty, it reads
MC> "Actually, the CLR guarantees to start running the static
MC> constructor before anything else is done with your class. However,
MC> it only guarantees to *start* running the static constructor; it
MC> doesn't actually guarantee to *finish* running it." Page 82, Chap 4
MC> Classes and Objects.
MC>
MC> If it is true, then it is possible that some static fields are not
MC> initialized (by static constructor) when they are used by other
MC> methods. It is terrible.
MC>
MC> Actually, I met some problem about static construtor. I have one
MC> WebService with one static memeber log-writer. The log-writer is
MC> initialized in static constructor with log file name. From time to
MC> time, invocation of webmethod of the service will raise exception.
MC> According to the prints of the exception, it is originated from
MC> static constructor. It says that the log file is already opened by
MC> another process and a Win32 IO Error is generated. That is absurd,
MC> since the log file is only supposed to be used by the webservice.
MC>
MC> This issue cannot be re-produced all the time. If Jesse Liberty is
MC> right, it may explain something. The static construtor is *invoked*
MC> before the WebService class is used. However, the execuation hangs
MC> for some reason. The webservice run to work. some time later, the
MC> static constructor execution resumes and bump into opening the log
MC> file. Oops, conflict!
MC>
MC> Just my guess. Is there anyone else meet similar situation?
MC>
MC> -Morgan
MC>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour
"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
See Jon's explanations there http://www.yoda.arachsys.com/csharp/beforefieldinit.html
MC> In the book *Programming C#* 4th editionby Jesse Liberty, it reads
MC> "Actually, the CLR guarantees to start running the static
MC> constructor before anything else is done with your class. However,
MC> it only guarantees to *start* running the static constructor; it
MC> doesn't actually guarantee to *finish* running it." Page 82, Chap 4
MC> Classes and Objects.
MC>
MC> If it is true, then it is possible that some static fields are not
MC> initialized (by static constructor) when they are used by other
MC> methods. It is terrible.
MC>
MC> Actually, I met some problem about static construtor. I have one
MC> WebService with one static memeber log-writer. The log-writer is
MC> initialized in static constructor with log file name. From time to
MC> time, invocation of webmethod of the service will raise exception.
MC> According to the prints of the exception, it is originated from
MC> static constructor. It says that the log file is already opened by
MC> another process and a Win32 IO Error is generated. That is absurd,
MC> since the log file is only supposed to be used by the webservice.
MC>
MC> This issue cannot be re-produced all the time. If Jesse Liberty is
MC> right, it may explain something. The static construtor is *invoked*
MC> before the WebService class is used. However, the execuation hangs
MC> for some reason. The webservice run to work. some time later, the
MC> static constructor execution resumes and bump into opening the log
MC> file. Oops, conflict!
MC>
MC> Just my guess. Is there anyone else meet similar situation?
MC>
MC> -Morgan
MC>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour
"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche