优化模块资源释放与异步预加载

This commit is contained in:
2026-09-03 14:16:48 +08:00
parent a263522b47
commit fddab16bd2
35 changed files with 1553 additions and 977 deletions
@@ -247,13 +247,25 @@ namespace Lskj.Control.BrowserSetting
/// <param name="args">The arguments.</param>
public static void AddModuleToTab(DllModule module, string[] args)
{
StaticControl.ModuleResourceScope moduleScope = null;
try
{
string guid = Guid.NewGuid().ToString();
XtraTabPage tp = new XtraTabPage();
moduleScope = new StaticControl.ModuleResourceScope(guid);
StaticControl.AttachModuleScope(tp, moduleScope);
moduleScope.Register(tp, () =>
{
if (!tp.IsDisposed)
tp.Dispose();
});
ERPInfo.Instance.selectFormModleId = module.Id;
IForm iform = FormHelper.LoadDllForm(module.DllName, args);
IForm iform;
using (StaticControl.PushModuleScope(moduleScope))
{
iform = FormHelper.LoadDllForm(module.DllName, args);
}
// 菜单打开的模块默认最大化,界面FormState设置为Normal模式,否则会出现界面不是全屏,会显示默认阴影界面
//iform.SubForm.WindowState = _frmMain.WindowState;
iform.SubForm.WindowState = FormWindowState.Normal; ;
@@ -278,28 +290,26 @@ namespace Lskj.Control.BrowserSetting
tp.ShowCloseButton = DefaultBoolean.True;
tp.Dock = DockStyle.Fill;
//module.Tag = "1";
module.Tag = guid;
module.ModuleForm = form;
form.Show();
StaticControl.RegisterModulePage(module, tp, form);
// OnLoad may create additional non-visual helpers. Keep the
// module scope active until the form has finished loading so
// those helpers are registered with the same page lifetime.
using (StaticControl.PushModuleScope(moduleScope))
{
form.Show();
}
if (args != null && !string.IsNullOrEmpty(args[4] + ""))
{
ModuleModel moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(args[4] + ""));
if (!string.IsNullOrEmpty(moduleModel.SearchCondFormModuleCode))
{
ModuleConditionsPanelEx mcpex = new ModuleConditionsPanelEx();
mcpex.InitializeControl(new ModuleModel(MainImpl.GetSystemdllTab(moduleModel.SearchCondFormModuleCode)), null, null, true);
if (StaticControl.ConditionsPanelDic.ContainsKey(args[4] + ""))
using (ModuleConditionsPanelEx mcpex = new ModuleConditionsPanelEx())
{
StaticControl.ConditionsPanelDic[args[4] + ""].Dispose();
StaticControl.ConditionsPanelDic[args[4] + ""] = mcpex;
mcpex.InitializeControl(new ModuleModel(MainImpl.GetSystemdllTab(moduleModel.SearchCondFormModuleCode)), null, null, true);
StaticControl.RegisterConditionPanel(args[4] + "", mcpex);
DialogResult dialogResult = mcpex.ShowDialog();
}
else
{
StaticControl.ConditionsPanelDic.Add(args[4] + "", mcpex);
}
DialogResult dialogResult = mcpex.ShowDialog();
}
}
ERPInfo.Instance.AddModulePage(tp);
@@ -309,6 +319,8 @@ namespace Lskj.Control.BrowserSetting
}
catch (Exception ex)
{
if (moduleScope != null)
moduleScope.Dispose();
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
LogHelper.Instance.WriteError(ex);