From 420b2420067c8becd77a3cf64d2d0a0f933912e0 Mon Sep 17 00:00:00 2001 From: 10191 <506754232@qq.com> Date: Tue, 9 Jun 2026 15:47:01 +0800 Subject: [PATCH] 11 --- HJGL_ZH/BLL/Funs.cs | 33 +++++++++++++++++++----- HJGL_ZH/FineUIPro.Web/common/PageBase.cs | 4 ++- 2 files changed, 29 insertions(+), 8 deletions(-) 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(); } }