fix(legacy): release hosted module resources safely
This commit is contained in:
@@ -634,6 +634,7 @@ namespace Lskj.Control
|
||||
// 模块级清理只解除事件和菜单引用。GridControl/GridView 的生命周期
|
||||
// 由真正的 WinForms 父容器负责,并在 Dispose(bool) 中统一结束。
|
||||
DetachGridViewEventHandlers();
|
||||
DisposeOwnedLookupFormsForDispose();
|
||||
if (gridViewRightMenu != null)
|
||||
{
|
||||
gridViewRightMenu.ReleaseResourcesForDispose();
|
||||
@@ -683,6 +684,70 @@ namespace Lskj.Control
|
||||
LabPicUrlPreview.Detach(gridView);
|
||||
}
|
||||
|
||||
private void DisposeOwnedLookupFormsForDispose()
|
||||
{
|
||||
HashSet<Form> forms = new HashSet<Form>();
|
||||
foreach (FrmModelLookUp2 modelLookUp in
|
||||
selectReturnModelLookUpCache.Values.Distinct())
|
||||
{
|
||||
if (modelLookUp != null)
|
||||
{
|
||||
forms.Add(modelLookUp);
|
||||
}
|
||||
}
|
||||
|
||||
selectReturnModelLookUpCache.Clear();
|
||||
selectReturnDisplaySourceCache.Clear();
|
||||
|
||||
RepositoryItem[] repositoryItems = null;
|
||||
try
|
||||
{
|
||||
if (gridControl != null)
|
||||
{
|
||||
repositoryItems = gridControl.RepositoryItems
|
||||
.Cast<RepositoryItem>()
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// The inner control may already be disposing its repository collection.
|
||||
}
|
||||
|
||||
if (repositoryItems != null)
|
||||
{
|
||||
foreach (RepositoryItemButtonEdit buttonEditor in
|
||||
repositoryItems.OfType<RepositoryItemButtonEdit>())
|
||||
{
|
||||
foreach (EditorButton button in buttonEditor.Buttons)
|
||||
{
|
||||
Form form = button.Tag as Form;
|
||||
if (form == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
button.Tag = null;
|
||||
forms.Add(form);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Form form in forms)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!form.IsDisposed)
|
||||
{
|
||||
form.Dispose();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// A helper form must not prevent its owning grid from closing.
|
||||
}
|
||||
}
|
||||
}
|
||||
private void DisposeGridResources()
|
||||
{
|
||||
if (_gridResourcesDisposed)
|
||||
@@ -723,6 +788,7 @@ namespace Lskj.Control
|
||||
mControlList.Clear();
|
||||
ColumnList.Clear();
|
||||
AutoPadDataReleColList.Clear();
|
||||
DisposeOwnedLookupFormsForDispose();
|
||||
FrozenColumns.Clear();
|
||||
ImageList.Clear();
|
||||
RepeatedVerificationNames.Clear();
|
||||
|
||||
Reference in New Issue
Block a user