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