diff --git a/SGGL/BLL/Common/Funs.cs b/SGGL/BLL/Common/Funs.cs index df9536a4..498e943f 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 { @@ -148,7 +149,7 @@ namespace BLL { 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 Model.SGGLDB(connString)); } // DBList[System.Threading.Thread.CurrentThread.ManagedThreadId].CommandTimeout = 1200; diff --git a/SGGL/WebAPI/Filter/TestPermissionAttribute.cs b/SGGL/WebAPI/Filter/TestPermissionAttribute.cs index f0baa379..0d62f7a4 100644 --- a/SGGL/WebAPI/Filter/TestPermissionAttribute.cs +++ b/SGGL/WebAPI/Filter/TestPermissionAttribute.cs @@ -106,14 +106,15 @@ namespace WebAPI.Filter } if (!isOk) { - if (BLL.Funs.DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId)) - { - BLL.Funs.DBList[System.Threading.Thread.CurrentThread.ManagedThreadId].Dispose(); - 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 ); + db.Dispose(); + } } ///