You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ProductionSystem/ProductionSystem_Service/Singleton.cs

31 lines
743 B
C#

namespace ProductionSystem_Service
{
/// <summary>
/// 单例模式
/// </summary>
/// <typeparam name="T"></typeparam>
public class Singleton<T> where T : class, new()
{
private static T _instance;
protected static readonly object SyncLock = new object();
public static T Instance
{
get
{
if (_instance == null)
{
lock (SyncLock)
{
if (_instance == null)
{
_instance = new T();
}
}
}
return _instance;
}
}
}
}