public class SingletonManager where T : class, new() { /// /// 私有静态实例 /// private static T instance; /// /// 用于同步的对象 /// private static readonly object mlock = new object(); /// /// 公共静态属性用于访问实例 /// public static T Instance { get { lock (mlock)//使用锁确保线程安全 { if (instance == null)//如果实例为空,则创建新实例 { instance = new T(); } return instance; } } } /// /// 释放单例 /// public virtual void ReleaseInstance() { if (instance != null) { instance = null; // 释放引用 } } }