If running multiple ASP.NET applications in the same application pool, how many instances will I have of a class\' static variable?
I know that every static variable lives for the lifetime of the App Domain.
So based on that, it will live per application pool process.
If running multiple ASP.NET applications in the same application pool, how many App Domains will I have?
Each application pool can have multiple worker processes, each worker process will run different application instances. Each instance of an application has a separate AppDomain
- so the answer to your original question is one per application instance.
Based on the fact that there will be one instance of a static variable per AppDomain, and regarding this (almost 10 year old) article by K. Scott Allen, there is one AppDomain per ASP.NET application, I will conclude that there will be one instance of each shared variable per ASP.NET Web application, even though they all run in the same application pool.
If introducing more worker processes, I would suspect this to be one instance per application per process it's running in.
Even though the code for both of the applications resides inside the same process, the unit of isolation is the .NET AppDomain. If there are classes with shared or static members, and those classes exist in both applications, each AppDomain will have it’s own copy of the static fields – the data is not shared.
(http://odetocode.com/Articles/305.aspx, see the section "AppDomains and you").
So, the answer to my original question would be 3), if running one worker process.