fix: 收敛旧模块资源释放与诊断
This commit is contained in:
+136
-13
@@ -62,6 +62,8 @@ namespace Lskj.Control
|
||||
/// 左侧表格查询条件
|
||||
/// </summary>
|
||||
private MyControl _leftGridSearchObj;
|
||||
private GridDragTree _gridDragTree;
|
||||
private bool mModuleResourcesReleased;
|
||||
|
||||
public bool IsExcel { get { return Model is DynamicExcelModel; } }
|
||||
/// <summary>
|
||||
@@ -152,6 +154,134 @@ namespace Lskj.Control
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void ReleaseResourcesForDispose()
|
||||
{
|
||||
if (mModuleResourcesReleased)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mModuleResourcesReleased = true;
|
||||
HashSet<ModuleGridDetailEx> details =
|
||||
new HashSet<ModuleGridDetailEx>();
|
||||
HashSet<ModuleGridEx> grids = new HashSet<ModuleGridEx>();
|
||||
foreach (System.Windows.Forms.Control control in
|
||||
EnumerateModuleControls(this))
|
||||
{
|
||||
ModuleGridDetailEx detail = control as ModuleGridDetailEx;
|
||||
if (detail != null)
|
||||
{
|
||||
details.Add(detail);
|
||||
}
|
||||
ModuleGridEx grid = control as ModuleGridEx;
|
||||
if (grid != null)
|
||||
{
|
||||
grids.Add(grid);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ModuleGridDetailEx detail in details)
|
||||
{
|
||||
detail.ReleaseResourcesForDispose();
|
||||
}
|
||||
foreach (ModuleGridEx grid in grids)
|
||||
{
|
||||
grid.SaveEvent -= SetDetailGridView;
|
||||
grid.OnExportCallBack -= SetExportGridView;
|
||||
grid.ReleaseResourcesForDispose();
|
||||
}
|
||||
|
||||
MyControl leftSearch = _leftGridSearchObj;
|
||||
_leftGridSearchObj = null;
|
||||
if (leftSearch != null)
|
||||
{
|
||||
leftSearch.OnDataSourceBindCallBack -= OnLeftControlObjDataSourceBindCallBack;
|
||||
leftSearch.Dispose();
|
||||
}
|
||||
|
||||
GridDragTree dragTree = _gridDragTree;
|
||||
_gridDragTree = null;
|
||||
if (dragTree != null)
|
||||
{
|
||||
dragTree.OnDragComplete -= OnDragTreeCompleted;
|
||||
dragTree.Dispose();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (treeLeft != null)
|
||||
{
|
||||
treeLeft.TreeNodeSelectAfter -= OnTreeLeftTreeNodeSelected;
|
||||
treeLeft.OnTreeNodeMouseDoubleClick -= TreeLeft_OnTreeNodeMouseDoubleClick;
|
||||
}
|
||||
if (gridLeft != null && gridLeft.GridView != null)
|
||||
{
|
||||
gridLeft.GridView.RowClick -= OnGridViewRowClick;
|
||||
}
|
||||
if (treeGridLeft != null && treeGridLeft.TreeListObj != null)
|
||||
{
|
||||
treeGridLeft.TreeListObj.Click -= TreeListObj_Click;
|
||||
treeGridLeft.TreeListObj.BeforeExpand -= TreeListObj_BeforeExpand;
|
||||
treeGridLeft.TreeListObj.BeforeCollapse -= TreeListObj_BeforeCollapse;
|
||||
}
|
||||
if (MainBodyTab != null)
|
||||
{
|
||||
MainBodyTab.SelectedPageChanged -= MainBodyTab_SelectedPageChanged;
|
||||
}
|
||||
if (excelControlEx1 != null)
|
||||
{
|
||||
excelControlEx1.SaveCallBack -= OnExcelSaveClick;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// A partially disposed child control must not stop cleanup.
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (Model != null && Model.DataCaches != null)
|
||||
{
|
||||
Model.DataCaches.Remove(this);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Cache cleanup must not interrupt module disposal.
|
||||
}
|
||||
|
||||
OnLeftGridViewRowClickCallBack = null;
|
||||
OnLeftTreeViewRowClickCallBack = null;
|
||||
if (Details != null)
|
||||
{
|
||||
Details.Clear();
|
||||
}
|
||||
LeftRowObj = null;
|
||||
ColumnNameTable = null;
|
||||
_currentRow = null;
|
||||
ExcelControlObj = null;
|
||||
Model = null;
|
||||
SysModel = null;
|
||||
}
|
||||
|
||||
private static IEnumerable<System.Windows.Forms.Control>
|
||||
EnumerateModuleControls(System.Windows.Forms.Control parent)
|
||||
{
|
||||
if (parent == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
foreach (System.Windows.Forms.Control child in parent.Controls)
|
||||
{
|
||||
yield return child;
|
||||
foreach (System.Windows.Forms.Control nested in
|
||||
EnumerateModuleControls(child))
|
||||
{
|
||||
yield return nested;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Excel 控件包含 SpreadsheetControl、BarManager 和命令注册项,
|
||||
/// 普通表格模块不应在设计器初始化阶段创建这些重型资源。
|
||||
@@ -249,9 +379,9 @@ namespace Lskj.Control
|
||||
if (Model.HasOperPrivilege() && model.IsBaseModule)
|
||||
{
|
||||
// 有权限则允许拖拽
|
||||
GridDragTree dragTree = new GridDragTree(this.ModuleGridObj.GridControlObj.GridView, this.treeLeft.TreeView);
|
||||
dragTree.CanDragParentNode = true;
|
||||
dragTree.OnDragComplete += new GridDragTreeCompleteEventHandler(OnDragTreeCompleted);
|
||||
this._gridDragTree = new GridDragTree(this.ModuleGridObj.GridControlObj.GridView, this.treeLeft.TreeView);
|
||||
this._gridDragTree.CanDragParentNode = true;
|
||||
this._gridDragTree.OnDragComplete += new GridDragTreeCompleteEventHandler(OnDragTreeCompleted);
|
||||
}
|
||||
if (this.SysModel.TreeDoubleClick)
|
||||
{
|
||||
@@ -477,7 +607,6 @@ namespace Lskj.Control
|
||||
{
|
||||
case 1:
|
||||
case 4://左侧为树节点
|
||||
this.ModuleGridObj.LeftTreeViewEx = this.treeLeft;
|
||||
Task<DataRow> baseLeftTreeFieldTask = cachesDic.AddTask(this, "BaseLeftTreeField", new Task<DataRow>(() =>
|
||||
{
|
||||
return BaseModuleImpl.GetBaseLeftTreeField(dynamicModel.ModuleCode);//获取表格左侧树字段
|
||||
@@ -531,12 +660,7 @@ namespace Lskj.Control
|
||||
DataTable customQueryFieldsTab = customQueryFieldsTask.Result;
|
||||
if (customQueryFieldsTab != null && customQueryFieldsTab.Rows.Count > 0)
|
||||
{
|
||||
Task<MyControl> leftGridSearchObjTask = cachesDic.AddTask(this, "LeftGridSearchObj", new Task<MyControl>(() =>
|
||||
{
|
||||
string searchSql = baseLeftTreeFieldTask.Result["fieldsql"] + "";
|
||||
return new MyControl(searchSql, sysModel.IsTreeTable ? this.treeGridLeft as GridControlEx : this.gridLeft);
|
||||
}));
|
||||
ModuleGridDetailObj._leftGridSearchObj = leftGridSearchObjTask.Result;
|
||||
// MyControl 必须由后续 UI 初始化阶段创建。
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -558,7 +682,7 @@ namespace Lskj.Control
|
||||
Task<DataTable> customColumnByDatabaseTask = cachesDic.AddTask(gridLeft, "CustomColumnByDatabase", new Task<DataTable>(() =>
|
||||
{
|
||||
string customColumKey = GridCustomColumnStruct.BaseLeftGridView + dynamicModel.ModuleCode;
|
||||
return gridLeft.GridView.GetCustomColumnByDatabase(customColumKey);
|
||||
return GridExtend.GetCustomColumnByDatabase(customColumKey);
|
||||
}));
|
||||
}
|
||||
else
|
||||
@@ -566,12 +690,11 @@ namespace Lskj.Control
|
||||
Task<DataTable> customColumnByDatabaseTask = cachesDic.AddTask(treeGridLeft, "CustomColumnByDatabase", new Task<DataTable>(() =>
|
||||
{
|
||||
string customColumKey = GridCustomColumnStruct.BaseLeftGridView + dynamicModel.ModuleCode;
|
||||
return treeGridLeft.GridView.GetCustomColumnByDatabase(customColumKey);
|
||||
return GridExtend.GetCustomColumnByDatabase(customColumKey);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
ModuleGridObj.LeftGridEx = sysModel.IsTreeTable ? this.treeGridLeft : this.gridLeft;
|
||||
break;
|
||||
}
|
||||
if (dynamicModel is DynamicExcelModel)//isExcel
|
||||
|
||||
Reference in New Issue
Block a user