What is the life span of a field in a static class?

佐手、 提交于 2019-12-23 01:58:20

问题


I have a simple web service, in it i have a static class which has a static collection to remember alive tokens.

I just want to make sure that the token collection lives until the next iisreset or the application pool recycles.

And what is the difference between remembering states in Application bag and static class?

Thanks,


回答1:


Microsoft (says):

ASP.NET includes application state primarily for compatibility with classic ASP so that it is easier to migrate existing applications to ASP.NET. It is recommended that you store data in static members of the application class instead of in the Application object. This increases performance because you can access a static variable faster than you can access an item in the Application dictionary.

So, use static variables. And do not forget use lock.




回答2:


Your static members won't scale to more than 1 server.



来源:https://stackoverflow.com/questions/4879023/what-is-the-life-span-of-a-field-in-a-static-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!