DIspose添加
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user