public class Single { private static readonly object obj = new object(); private static Single single; private Single(){ }//防止在类外实例化 public static Single GetSingle() { if (single == null) { lock (obj)//加锁防止某一时间片内有两个线程相继去实例化 { if (single == null) { single = new Single(); } } } return single; } }