Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question about static Objects .net

Tags:

c#

asp.net

iis-7

Are static variable values the same within one session or are their values the same at application server level?

like image 475
Ahsan Iqbal Avatar asked Dec 21 '22 11:12

Ahsan Iqbal


1 Answers

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)
like image 129
Jon Skeet Avatar answered Dec 24 '22 00:12

Jon Skeet