Wednesday 15 February 2012

c# - ASP.NET maintaining static variables -


Recently we have learned about the recycling app of IIS and this is their primary values ​​(null, 0s, etc. How does it affect the stable variable)

We use some static variables that are initialized for the first time in a static constructor (first for initialization, configuration values ​​such as "number of decimal places", "administrator email" etc.) and then Only read their values ​​with website execution.

What is the best way to solve this problem? Some possible ideas:

  • Variables in each recovery are zero / calibrate (due to possible display effect it is not + time spent to add this check to each variable Either way preventing AppDomain Recycling (This reset logic is not in Windows form with static forms, it should not work equally Language in both environments ? Values ​​as stable variable management

  • Using some other methods of catching these variables (but we think that some values ​​are used for all information. As a global context for users, stable variables were the best choice display / coding intelligent)

  • subscribing to any event triggered in those Appendaman recycling so that we can restart all those variables Can (maybe The best option if recycling can not be stopped ...)

    Thoughts?

    Checking the null wrapped in code:

      Public interface IMyConfig {string Var1 {get; } String Var2 {get; }} Public class MyConfig: IMyConfig {Private string _Var1; Private string _Var2; Public string Var1 {get {return _Var1; }} Public string Var2 {get {return _Var2; }} Private static object s_SyncRoot = new object (); Private static IMyConfig s_Instance; Receive public static IMyConfig example {private_miconfig} {// load_art 1, _Var2 variable} lock {s_Instance! } Return s_Instance; }}}    

No comments:

Post a Comment