diff --git a/SGGL/BLL/Common/Funs.cs b/SGGL/BLL/Common/Funs.cs
index c5ef078b..5ae3b85e 100644
--- a/SGGL/BLL/Common/Funs.cs
+++ b/SGGL/BLL/Common/Funs.cs
@@ -5,6 +5,7 @@ namespace BLL
using Quartz;
using RestSharp;
using System;
+ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
@@ -22,13 +23,13 @@ namespace BLL
///
/// 维护一个DB集合
///
- private static Dictionary dataBaseLinkList = new System.Collections.Generic.Dictionary();
+ private static ConcurrentDictionary dataBaseLinkList = new ConcurrentDictionary();
///
/// 维护一个DB集合
///
- public static System.Collections.Generic.Dictionary DBList
+ public static ConcurrentDictionary DBList
{
get
{
@@ -40,7 +41,7 @@ namespace BLL
get;
set;
}
- public static Dictionary WebEditList = new Dictionary();
+ public static ConcurrentDictionary WebEditList = new ConcurrentDictionary();
///
/// 数据库连接字符串
@@ -158,7 +159,7 @@ namespace BLL
// }
//}
- private static object locker = new object();
+ //private static object locker = new object();
///
/// 数据库上下文。
@@ -167,13 +168,13 @@ namespace BLL
{
get
{
- lock (locker)
+ // lock (locker)
{
try
{
if (!DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
{
- DBList.Add(System.Threading.Thread.CurrentThread.ManagedThreadId, new SGGLDB(connString));
+ DBList.TryAdd(System.Threading.Thread.CurrentThread.ManagedThreadId, new SGGLDB(connString));
}
// DBList[System.Threading.Thread.CurrentThread.ManagedThreadId].CommandTimeout = 1200;
@@ -188,7 +189,7 @@ namespace BLL
}
else
{
- DBList.Add(System.Threading.Thread.CurrentThread.ManagedThreadId, db);
+ DBList.TryAdd(System.Threading.Thread.CurrentThread.ManagedThreadId, db);
}
return db;
}
diff --git a/SGGL/BLL/ZHGL/RealName/RealNameMonitorService.cs b/SGGL/BLL/ZHGL/RealName/RealNameMonitorService.cs
index e0ab03e7..ed7221ed 100644
--- a/SGGL/BLL/ZHGL/RealName/RealNameMonitorService.cs
+++ b/SGGL/BLL/ZHGL/RealName/RealNameMonitorService.cs
@@ -235,7 +235,12 @@ namespace BLL
{
if (BLL.Funs.DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
{
- BLL.Funs.DBList.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
+ Model.SGGLDB db;
+ BLL.Funs.DBList.TryRemove(System.Threading.Thread.CurrentThread.ManagedThreadId,out db);
+ if (db != null)
+ {
+ db.Dispose();
+ }
}
}
}
diff --git a/SGGL/FineUIPro.Web/common/PageBase.cs b/SGGL/FineUIPro.Web/common/PageBase.cs
index b05f75d5..dcc27aa7 100644
--- a/SGGL/FineUIPro.Web/common/PageBase.cs
+++ b/SGGL/FineUIPro.Web/common/PageBase.cs
@@ -330,7 +330,12 @@ namespace FineUIPro.Web
{
if (BLL.Funs.DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
{
- BLL.Funs.DBList.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
+ Model.SGGLDB db ;
+ BLL.Funs.DBList.TryRemove(System.Threading.Thread.CurrentThread.ManagedThreadId,out db);
+ if (db != null)
+ {
+ db.Dispose();
+ }
}
if (BLL.SQLHelper.GetConn().State == ConnectionState.Open)
diff --git a/SGGL/WebAPI/Filter/TestPermissionAttribute.cs b/SGGL/WebAPI/Filter/TestPermissionAttribute.cs
index 3647a3cc..ab7799bb 100644
--- a/SGGL/WebAPI/Filter/TestPermissionAttribute.cs
+++ b/SGGL/WebAPI/Filter/TestPermissionAttribute.cs
@@ -138,13 +138,19 @@ namespace WebAPI.Filter
}
if (!isOk)
{
- if (BLL.Funs.DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
- {
- BLL.Funs.DBList.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
- }
+
base.OnActionExecuted(actionExecutedContext);
}
+ if (BLL.Funs.DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
+ {
+ Model.SGGLDB db;
+ BLL.Funs.DBList.TryRemove(System.Threading.Thread.CurrentThread.ManagedThreadId, out db);
+ if (db != null)
+ {
+ db.Dispose();
+ }
+ }
}
///