static void Main(string[] args) { var singelton = new Thread(() => ClassSingleton.GetInstance().helloSingleton()); var singelton1 = new Thread(() => ClassSingleton.GetInstance().helloSingleton()); singelton.Start(); singelton1.Start(); }
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); }