ASP.NET应用程序状态VS静态对象 [英] ASP.NET Application state vs a Static object

查看:243
本文介绍了ASP.NET应用程序状态VS静态对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个标准的ASP.NET应用程序,有没有做一个静态的对象,而不是把对象实例的应用状态之间有什么区别?

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?

这是我的理解,这两个对象ONCE存在的应用程序域。

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

其次,如果你在一个被引用的DLL静态对象会发生什么,对于一个ASP.NET网站。这也是该应用程序域的一部分,所以它会一直存在一次?

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?

推荐答案

从:<一href=\"http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312607\">http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312607

ASP.NET包括应用程序状态
  主要是为了与兼容性
  传统的ASP,使得它更容易
  迁移现有的应用程序
  ASP.NET。建议您
  在静态成员存储数据
  应用程序类,而不是在
  应用对象。这增加
  性能,因为您可以访问
  静态变量比你能更快
  在应用程序中访问某个项目
  字典。

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.

此外,是的,静态变量,无论他们来自哪里加载的行为相同的方式和每个应用程序域存在一次(除非你在谈论那些标记为[ThreadStatic])

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

这篇关于ASP.NET应用程序状态VS静态对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆