public void Run() { Console.WriteLine("Getting instance 1..."); var instance1 = AppSingleton.GetInstance(); Console.WriteLine("Done."); Console.WriteLine("Getting instance 2..."); var instance2 = AppSingleton.GetInstance(); Console.WriteLine("Done."); Console.WriteLine($"instance1 is the same object as instance2: {instance1 == instance2}"); }
public static AppSingleton GetInstance() { if (_singleInstance == null) { lock (_lockObject) { if (_singleInstance == null) { _singleInstance = new AppSingleton(); } } } return(_singleInstance); }