80 lines
1.6 KiB
C#
80 lines
1.6 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Configuration;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace Epost.DAL
|
||
{
|
||
public class DB_DLL
|
||
{
|
||
private static DataBaseOpration.OprationSqlDAL db;
|
||
/// <summary>
|
||
|
||
/// 程序运行时,创建一个静态只读的进程辅助对象
|
||
|
||
/// </summary>
|
||
|
||
private static readonly object _object = new object();
|
||
// //SqlLocDPSConnection
|
||
public static string _conn = ConfigurationManager.ConnectionStrings["SqlLocDPSConnection"].ConnectionString;
|
||
|
||
/// <summary>
|
||
|
||
/// 构造方法私有,外键不能通过New类实例化此类
|
||
|
||
/// </summary>
|
||
|
||
private DB_DLL()
|
||
|
||
{
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
|
||
/// 此方法是本类实例的唯一全局访问点
|
||
|
||
/// (双重加锁 Double-Check Locking)
|
||
|
||
/// </summary>
|
||
|
||
/// <returns></returns>
|
||
|
||
public static DataBaseOpration.OprationSqlDAL GetInstance()
|
||
{
|
||
|
||
//先判断实例是否存在,不存在再加锁处理
|
||
|
||
if (db == null)
|
||
|
||
{
|
||
|
||
//在同一时刻加了锁的那部分程序只有一个线程可以进入,
|
||
|
||
lock (_object)
|
||
|
||
{
|
||
|
||
//如实例不存在,则New一个新实例,否则返回已有实例
|
||
|
||
if (db == null)
|
||
|
||
{
|
||
|
||
db = new DataBaseOpration.OprationSqlDAL(_conn);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
return db;
|
||
|
||
}
|
||
|
||
}
|
||
}
|