コード例 #1
0
        private static void Method2()
        {
            Good.ChocolateBoiler boiler = Good.ChocolateBoiler.GetInstance();
            for (int i = 0; i < 10; i++)
            {
                boiler.Fiil();
                boiler.Boil();

                if (i % 2 != 0)
                {
                    boiler.Drain();
                }

                boiler.GetStatus();
                Thread.Sleep(2500);
            }
        }
コード例 #2
0
        public static ChocolateBoiler GetInstance()
        {
            if (Instance == null)
            {
                lock (syncRoot)
                {
                    if (Instance == null)
                    {
                        Instance = new ChocolateBoiler();
                        Console.WriteLine($"Thread {Thread.CurrentThread.Name} was created Instance this class");
                        return(Instance);
                    }
                }
            }

            Console.WriteLine($"Thread {Thread.CurrentThread.Name} got Instance this class");
            return(Instance);

            //return Instance ?? (Instance = new ChocolateBoiler());
        }