C#多线程Singleton(单件)模式模板
时间:2021-07-31 08:03:56|栏目:.NET代码|点击: 次
复制代码 代码如下:
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();
}
上一篇:.Net获取IP地址的方法
栏 目:.NET代码
下一篇:Visual Studio 2017正式版发布 亮点看这里
本文地址:http://www.codeinn.net/misctech/162932.html






