private void TestLock() { var s = SingletonWithLock.GetInstance(); //var s = SingletonWithInterface.GetInstance(); //var s = Singleton.GetInstance(); //Console.WriteLine(s.GetValue()); Thread.Sleep(1000); }
public static SingletonWithLock GetInstance() { if (_instance == null) { lock (_syncRoot) { if (_instance == null) { _instance = new SingletonWithLock(); Console.WriteLine("Created a new instance from null"); } } } else { Console.WriteLine("Just return exists value"); } return(_instance); }