/// <summary>
/// 單例類助手
/// </summary>
public sealed class SingletonHelper<T> where T : new()
{
private static T instance = new T();
private static object locker = new object();
private SingletonHelper() { }
/// <summary>
/// 獲取單例
/// </summary>
/// <returns></returns>
public static T GetInstance()
{
if (null == instance)
{
lock (locker)
{
if (null == instance)
{
instance = new T();
}
}
}
return instance;
}
/// <summary>
/// 設置單例
/// </summary>
/// <param name=
public void SetInstance(T value)
{
instance = value;
}
}
From:http://tw.wingwit.com/Article/program/net/201311/13636.html