SiteMap  | About    

Static variables, what is their life span?

The time during which a variable retains its value is known as its lifetime . The value of a variable may change over its lifetime, but it retains some value. When a variable loses scope, it no longer has a value. Static fields are (unless [ThreadStatic]) one instance per app-domain, meaning: all requests hare the same value. By default, if the application itself does not receive any requests for 20 minutes, it will unload from memory. All static variables will then be lost; on the next request to the app, a new app instance will get loaded.

Similar to how a session expires when a user stops making requests, an application instance can also expire. The AppDomain won't be collected while assigned to the static field, and will expire if the App-Pool recycles in IIS. (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.