Exemplo n.º 1
0
        public void TestSameInstances()
        {
            SingletonProcess s = SingletonProcess.Instance();
            SingletonProcess p = SingletonProcess.Instance();

            Assert.AreSame(s, p);
        }
Exemplo n.º 2
0
 public static SingletonProcess Instance()
 {
     if (_instance == null)
     {
         _instance = new SingletonProcess();
     }
     return(_instance);
 }
Exemplo n.º 3
0
        public void TestSameInstancesPerThread()
        {
            SingletonProcess s = SingletonProcess.Instance();

            object s1 = null;
            object s2 = null;

            var thr1 = new Thread(() => { s1 = SingletonProcess.Instance(); });

            thr1.Start();
            thr1.Join();

            var thr2 = new Thread(() => { s2 = SingletonProcess.Instance(); });

            thr2.Start();
            thr2.Join();

            Assert.AreSame(s, s1);
            Assert.AreSame(s, s2);
            Assert.AreSame(s1, s2);
        }