开发者

ASP.Net class loading questions

开发者 https://www.devze.com 2023-01-17 16:14 出处:网络
1) In a standard .Net application, are classes loaded as they are required? (e.g. If I have a class with a static constructor, is that static constructor only run the first time that class is needed?)

1) In a standard .Net application, are classes loaded as they are required? (e.g. If I have a class with a static constructor, is that static constructor only run the first time that class is needed?)

2) In an ASP.Net MVC (or web forms) application, is the static constructor invoked on every request that uses it? Or is it only for the first request that uses it?

3) In general, what is the开发者_Go百科 lifetime of an ASP.Net application? Is each request a separate execution? Is anything persisted from request to request?

As you can see, I don't have a good understanding of when/how classes are loaded by the .Net runtime, and I was having trouble articulating the right Google query for this. If someone can point me to general documentation on the subject, I would be most appreciative.


  1. For the most part, yes. But you have no control over when the static constructor is executed, except for the guarantee that it will be executed prior to it being used for the first time and that it will be thread-safe.
  2. No. Only the first time it's accessed, once per application domain.
  3. The lifetime of a .Net app depends on IIS application pool settings and the stability of the application. There is an IIS setting that can force an application to recycle which may cause the application to restart. And of course the application can also crash, such as by an unmanaged library, which too will cause a restart.
0

精彩评论

暂无评论...
验证码 换一张
取 消