public void TestSameInstances() { SingletonProcess s = SingletonProcess.Instance(); SingletonProcess p = SingletonProcess.Instance(); Assert.AreSame(s, p); }
public static SingletonProcess Instance() { if (_instance == null) { _instance = new SingletonProcess(); } return(_instance); }
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); }