public MySingleObj GetInstance() { if (obj == null) { obj = new MySingleObj(); } return(obj); }
/// <summary> /// 线程安全 /// </summary> /// <returns></returns> public MySingleObj GetInstance1() { //过滤掉是null的 if (obj == null) { //多个线程 都是null的话让一个进来 lock (lockobj) { //实例化一次 if (obj == null) { obj = new MySingleObj(); } } } return(obj); }