Ejemplo n.º 1
0
 private static void Singleton()
 {
     SingleTonSample.InstanceCreation();
     SingleTonSample.InstanceCreation();
     Console.ReadLine();
     //throw new NotImplementedException();
 }
Ejemplo n.º 2
0
        public static SingleTonSample InstanceCreation()
        {
            //singleTonObject = new Lazy<SingleTonSample>(() => new SingleTonSample()
            //     );

            //return singleTonObject.Value;

            if (singleTonObject == null)
            {
                lock (lockingObject)
                {
                    if (singleTonObject == null)
                    {
                        singleTonObject = new SingleTonSample();
                        //  Console.WriteLine("Singleton instance is created.");
                    }
                }
            }
            return(singleTonObject);
        }