ASP.NET Application state vs a Static object

Deadly 提交于 2019-11-26 10:31:06

问题


if i have a standard ASP.NET application, is there any difference between making an object static as opposed to putting the object instance in the Application state?

from my understanding, both objects exist ONCE for the app domain.

Secondly, what happens if you have a static object in a referenced dll, for an ASP.NET site. It\'s also part of the app domain, so it will always exist once?


回答1:


From: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312607

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.

Also, yes, static variables behave the same way regardless of where they are loaded from, and exist exactly once per app domain (unless you're talking about those labeled [ThreadStatic])



来源:https://stackoverflow.com/questions/303725/asp-net-application-state-vs-a-static-object

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