简体   繁体   中英

Question about static Objects .net

静态变量值在一个会话中是相同的还是它们的值在应用程序服务器级别相同?

They're at an AppDomain level - that's the same for all static variables, whether they're in ASP.NET or not.

So:

  • If you use the same class from different AppDomains, you'll get separate variables
  • If your AppDomain is recycled, you'll get separate variables
  • If two requests go to different machines, you'll get separate variables
  • If two concurrent requests hit the same AppDomain, they can mess with each other (so things like count++ aren't safe)

我认为只要iis进程存在,静态变量就会保持其值

在重新启动应用程序之前,该变量仍将在内存中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM