Esempio n. 1
0
 public static Singleton2 GetBadInstance()
 {
     if (badInstance == null)
     {
         lock (syncLocker)
         {
             Task.Delay(5000).Wait();
             badInstance = new Singleton2();
         }
     }
     return(badInstance);
 }
Esempio n. 2
0
 public static Singleton2 GetInstance()
 {
     // 第一重判断
     if (instance == null)
     {
         // 锁定代码块
         lock (syncLocker)
         {
             // 第二重判断
             if (instance == null)
             {
                 instance = new Singleton2();
             }
         }
     }
     return(instance);
 }