diff --git a/HJGL_ZH/BLL/Funs.cs b/HJGL_ZH/BLL/Funs.cs index 36bb3e5..6ec762f 100644 --- a/HJGL_ZH/BLL/Funs.cs +++ b/HJGL_ZH/BLL/Funs.cs @@ -1,9 +1,11 @@ namespace BLL { + using Model; using System; + using System.Collections.Concurrent; using System.Collections.Generic; - using System.Globalization; using System.Data.Linq; + using System.Globalization; /// /// 通用方法类。 @@ -13,12 +15,12 @@ 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 { @@ -125,12 +127,29 @@ namespace BLL { get { - if (!DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId)) + try { - DBList.Add(System.Threading.Thread.CurrentThread.ManagedThreadId, new Model.SGGLDB(connString)); - } + if (!DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId)) + { + DBList.TryAdd(System.Threading.Thread.CurrentThread.ManagedThreadId, new SGGLDB(connString)); + } - return DBList[System.Threading.Thread.CurrentThread.ManagedThreadId]; + //DBList[System.Threading.Thread.CurrentThread.ManagedThreadId].CommandTimeout = 120; + return DBList[System.Threading.Thread.CurrentThread.ManagedThreadId]; + } + catch + { + var db = new SGGLDB(connString); + if (DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId)) + { + DBList[System.Threading.Thread.CurrentThread.ManagedThreadId] = db; + } + else + { + DBList.TryAdd(System.Threading.Thread.CurrentThread.ManagedThreadId, db); + } + return db; + } } } diff --git a/HJGL_ZH/FineUIPro.Web/common/PageBase.cs b/HJGL_ZH/FineUIPro.Web/common/PageBase.cs index 099c0cc..9cc9588 100644 --- a/HJGL_ZH/FineUIPro.Web/common/PageBase.cs +++ b/HJGL_ZH/FineUIPro.Web/common/PageBase.cs @@ -165,7 +165,9 @@ namespace FineUIPro.Web { if (BLL.Funs.DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId)) { - BLL.Funs.DBList.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId); + Model.SGGLDB outdb; + BLL.Funs.DBList.TryRemove(System.Threading.Thread.CurrentThread.ManagedThreadId, out outdb); + outdb.Dispose(); } }