Piccola modifica al codice che avevo postato in "
La Cache e oggetti singleton" perchè non si sa mai che la 
CacheItemRemovedCallback scatti prima che la funzione sia riuscita a tornare l'istanza statica e quindi vi ritroviate con un bel 
NullReferenceException.
class C
{
   static C c_currentInstance;
   
   public static C Current
   {
      C instance =  c_currentInstance;
      if(instance == null)
      {
         instance = new C();
         c_currentInstance = instance;
         HttpContext.Current.Cache.Add("c_currentInstance", instance, [cut], 
           new CacheItemRemovedCallback(OnCacheItemRemovedCallback));
      }
      return instance;
   }
   static void OnCacheItemRemovedCallback([cut])
   {
       c_currentInstance = null;
   }
}
		
			posted @ mercoledì 26 aprile 2006 16:52