Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Console.WriteLine("__________________________ SingleTon with Thread Lock__________________________");
            ///SingleTon with Thread Lock use to preserve there should only one instance

            Parallel.Invoke(
                () => FirstThread(),
                () => SecondThread()
                );

            Console.WriteLine("__________________________ Simple SingleTon __________________________");

            SingleTon obj = SingleTon.GetInstance;

            obj.PrintDetails("First obj");

            SingleTon obj1 = SingleTon.GetInstance;

            obj.PrintDetails("Second obj");


            new Program().CallFactory();

            new Program().CallFactoryMethod();

            Console.ReadLine();
        }
Пример #2
0
        private static void FirstThread()
        {
            SingleTon obj = SingleTon.GetInstance;

            obj.PrintDetails("Thread First obj");
        }
Пример #3
0
        private static void SecondThread()
        {
            SingleTon obj = SingleTon.GetInstance;

            obj.PrintDetails("Thread Second obj");
        }