开发者

Question about static Objects .net

开发者 https://www.devze.com 2023-03-22 19:39 出处:网络
Are static开发者_如何学C variable values the same within one session or are their values the same at application server level?They\'re at an AppDomain level - that\'s the same for all static variables

Are static开发者_如何学C variable values the same within one session or are their values the same at application server level?


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)


I think as long as iis process is there the static variable will hold its value


The variable will still in memory until the restart of the application.

0

精彩评论

暂无评论...
验证码 换一张
取 消