예제 #1
0
        static void Main(string[] args)
        {
            var singelton = new Thread(() => ClassSingleton.GetInstance().helloSingleton());

            var singelton1 = new Thread(() => ClassSingleton.GetInstance().helloSingleton());

            singelton.Start();
            singelton1.Start();
        }
예제 #2
0
        public static ClassSingleton GetInstance()
        {
            if (instance == null)
            {
                lock (lockobj)
                {
                    if (instance == null)
                    {
                        Random ran = new Random();
                        instance = new ClassSingleton(ran.Next(1, 5));
                    }
                }
            }

            return(instance);
        }