添加项目文件。
This commit is contained in:
80
Epost.DAL/DB_Mysql.cs
Normal file
80
Epost.DAL/DB_Mysql.cs
Normal file
@ -0,0 +1,80 @@
|
||||
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_MySql
|
||||
{
|
||||
private static DataBaseOpration.OprationMySqlDAL db;
|
||||
/// <summary>
|
||||
|
||||
/// 程序运行时,创建一个静态只读的进程辅助对象
|
||||
|
||||
/// </summary>
|
||||
|
||||
private static readonly object _object = new object();
|
||||
// //SqlLocDPSConnection
|
||||
public static string _conn = ConfigurationManager.ConnectionStrings["MysqlLocDPSConnection"].ConnectionString;
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// 构造方法私有,外键不能通过New类实例化此类
|
||||
|
||||
/// </summary>
|
||||
|
||||
private DB_MySql()
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// 此方法是本类实例的唯一全局访问点
|
||||
|
||||
/// (双重加锁 Double-Check Locking)
|
||||
|
||||
/// </summary>
|
||||
|
||||
/// <returns></returns>
|
||||
|
||||
public static DataBaseOpration.OprationMySqlDAL GetInstance()
|
||||
{
|
||||
|
||||
//先判断实例是否存在,不存在再加锁处理
|
||||
|
||||
if (db == null)
|
||||
|
||||
{
|
||||
|
||||
//在同一时刻加了锁的那部分程序只有一个线程可以进入,
|
||||
|
||||
lock (_object)
|
||||
|
||||
{
|
||||
|
||||
//如实例不存在,则New一个新实例,否则返回已有实例
|
||||
|
||||
if (db == null)
|
||||
|
||||
{
|
||||
|
||||
db = new DataBaseOpration.OprationMySqlDAL(_conn);
|
||||
// db.SetLogPath(@"E:\Log\text1.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return db;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user