private static volatile T _instance = null;
private static object objLock = new Object();
private T()
{
}
public static T Instance
{
get
{
if (_instance == null)
{
lock (objLock)
{
if (_instance == null)
{
_instance = new T();
}
}
}
return _instance;
}
}
在必要的时候需如果要刷新当前instance,可以这样写:
代码如下:
public static void RefreshInstance()
{
_instance = new T();
}
查看更多关于C#多线程Singleton(单件)模式模板的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did35174
C#多线程Singleton(单件)模式模板
代码如下:
阅读:45次