Sic.Framework-Nanjing-Baishi/MECF.Framework.Common/Aitex/Core/Util/Singleton.cs

31 lines
419 B
C#
Raw Normal View History

2023-04-13 11:51:03 +08:00
using System;
namespace Aitex.Core.Util
{
[Serializable]
public class Singleton<T> where T : class, new()
{
private static volatile T instance;
private static object locker = new object();
public static T Instance
{
get
{
if (instance == null)
{
lock (locker)
{
if (instance == null)
{
instance = new T();
}
}
}
return instance;
}
}
}
}