ASP.NET中的静态变量 [英] Static variables in ASP.NET
问题描述
有的建议来存储静态成员ASP.NET应用程序状态的文章中的的HttpApplication 的类(在Global.asax.cs中)。
There is an article that recommends to store ASP.NET application state in static members of HttpApplication class (in Global.asax.cs).
有关的静态成员存储应用程序状态什么的其他类
What about storing application state in static members of other classes?
我试过这样做,似乎有这些变量的多个实例可以存在(每个AppDomain单一实例?)。这是真的,我们应该始终只使用的应用程序的类的静态字段?还是不要紧?
I tried to do so and it seems that there are several instances of these variables can exist (single instance per AppDomain?). Is it true and should we always use only Application class's static fields? Or it doesn't matter?
推荐答案
它的工作原理pretty很好,它比在许多情况下,应用程序
更好的(它是强类型的,例如)。只要确保你知道线程和锁定问题的。
It works pretty well and it's better than Application
in many cases (it's strongly typed, for instance). Just make sure you are aware of threading and locking issues.
作为一个个人的经验,我已经成功地缓存配置信息在静态ASP.NET应用程序
类一对夫妇的网站。
As a personal experience, I've managed to cache configuration information for ASP.NET app in a static
class in a couple Web sites.
这篇关于ASP.NET中的静态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!