public staitc SyncLazySingleton GetInstance() { //先检查实例是否存在,如果不存在才进入下面的同步块 if (_instance == null) { //同步块,线程安全的创建实例 lock (_instance) { //再次检查实例是否存在,如果不存在才真正的创建实例 if (_instance = null) { _instance = new SyncLazySingleton(); } } } return(_instance); }
void static Main(string[] args) { SyncLazySingleton.GetInstance(); }