DIspose添加

This commit is contained in:
hsc
2026-06-11 15:45:29 +08:00
parent 9c661200b9
commit 5cac253cb8
8 changed files with 164 additions and 17 deletions

View File

@@ -18,7 +18,7 @@ using UIShare.GlobalVariable;
namespace TestingModule.ViewModels
{
public class SingleStepEditViewModel:NavigateViewModelBase
public class SingleStepEditViewModel:NavigateViewModelBase,IDisposable
{
#region
private Guid _ID;
@@ -196,6 +196,26 @@ namespace TestingModule.ViewModels
SelectedStep = new StepVM(_ScopedContext.SelectedStep);
}
#endregion
public void Dispose()
{
try
{
// 1. 【核心修复】必须严格退订所有全局 Prism 事件
_eventAggregator?.GetEvent<EditSetpEvent>()?.Unsubscribe(EditSingleStep);
_eventAggregator?.GetEvent<DeletedStepEvent>()?.Unsubscribe(DisposeSelectedStep);
_eventAggregator?.GetEvent<ParamsChangedEvent>()?.Unsubscribe(ParamsChanged);
// 2. 清空当前正在编辑的步骤副本,断开前台绑定,防止 UI 视图树悬挂
SelectedStep = null!;
// 3. 断开对工位隔离上下文的强引用
_ScopedContext = null!;
}
catch (Exception ex)
{
LoggerHelper.Error($"释放单步编辑组件SingleStepEditViewModel资源失败: {ex.Message}");
}
}
}
}