static void TestSimple() { SingltonClass s1 = SingltonClass.GetInstance(); Console.WriteLine(s1.GetHashCode()); SingltonClass s2 = SingltonClass.GetInstance(); Console.WriteLine(s2.GetHashCode()); }
static void TestThresd() { (new Thread(() => { SingltonClass s1 = SingltonClass.GetInstance(); Console.WriteLine(s1.GetHashCode()); })).Start(); SingltonClass s2 = SingltonClass.GetInstance(); Console.WriteLine(s2.GetHashCode()); }
public static SingltonClass GetInstance() { if (_singltonClass == null) { lock (_locker) { if (_singltonClass == null) { _singltonClass = new SingltonClass(); } } } return(_singltonClass); }