ASP.NET Application state vs a Static object

前端 未结 1 538
说谎
说谎 2020-11-30 00:05

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?

相关标签:
1条回答
  • 2020-11-30 00:27

    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])

    0 讨论(0)
提交回复
热议问题