diff --git a/ADP/ViewModels/ShellViewModel.cs b/ADP/ViewModels/ShellViewModel.cs
index 86e9243..a09cd54 100644
--- a/ADP/ViewModels/ShellViewModel.cs
+++ b/ADP/ViewModels/ShellViewModel.cs
@@ -50,13 +50,11 @@ namespace ADP.ViewModels
set => SetProperty(ref _IsLeftDrawerOpen, value);
}
- // 代理属性:动态反映当前被激活的 Scope 状态
public TimeSpan RunningTime
{
get
{
if (CurrentContext == null) return TimeSpan.Zero;
- // 💡 核心:如果当前工位的计时器正在跑,动态累加 SW 当前的时间,否则返回其保存的固定时间值
return CurrentContext.SW.IsRunning ? CurrentContext.SW.Elapsed : CurrentContext.RunningTime;
}
set
diff --git a/SettingModule/Views/SettingView.xaml b/SettingModule/Views/SettingView.xaml
index 9da1d2b..aa99955 100644
--- a/SettingModule/Views/SettingView.xaml
+++ b/SettingModule/Views/SettingView.xaml
@@ -448,7 +448,7 @@
diff --git a/TestingModule/Views/StepsManager.xaml b/TestingModule/Views/StepsManager.xaml
index b8a68b6..e041dbc 100644
--- a/TestingModule/Views/StepsManager.xaml
+++ b/TestingModule/Views/StepsManager.xaml
@@ -22,6 +22,9 @@
标记是否已被注销,执行方法据此安全退出
+ private volatile bool _disposed = false;
+
private Guid TestRoundID;
public StepRunning(ScopedContext ScopedContext, SystemConfig systemConfig,IEventAggregator eventAggregator, DeviceManager deviceManager)
{
@@ -50,6 +53,7 @@ namespace UIShare
}
public async Task ExecuteErrorSteps(ProgramVM program, int depth = 0, CancellationToken cancellationToken = default)
{
+ if (_disposed) return false;
int index = 0;
bool stepSuccess = false;
if (depth == 0)
@@ -67,7 +71,7 @@ namespace UIShare
while (index < program.ErrorStepCollection.Count)
{
- if (cancellationToken.IsCancellationRequested)
+ if (_disposed || cancellationToken.IsCancellationRequested)
{
break;
}
@@ -215,6 +219,7 @@ namespace UIShare
}
public async Task ExecuteSteps(ProgramVM program, int depth = 0, CancellationToken cancellationToken = default)
{
+ if (_disposed) return false;
int index = 0;
bool stepSuccess = false;
if (depth == 0)
@@ -232,11 +237,11 @@ namespace UIShare
while (index < program.StepCollection.Count)
{
- while (_scopedContext.IsStop == true)
+ while (!_disposed && _scopedContext.IsStop == true)
{
- await Task.Delay(50);
+ await Task.Delay(50, cancellationToken);
}
- if (cancellationToken.IsCancellationRequested)
+ if (_disposed || cancellationToken.IsCancellationRequested)
{
break;
}
@@ -392,11 +397,12 @@ namespace UIShare
public async Task ExecuteMethodStep(StepVM step, Dictionary parameters, int depth, CancellationToken cancellationToken = default)
{
+ if (_disposed) return;
try
{
if(_scopedContext.Program.StepCollection.Count>1)
_scopedContext.SelectedStep = null;
- await Task.Delay(_systemConfig.PerformanceLevel);
+ await Task.Delay(_systemConfig.PerformanceLevel, cancellationToken);
// 1. 查找类型
@@ -711,7 +717,41 @@ namespace UIShare
}
}
-
+ public void Dispose()
+ {
+ if (_disposed) return;
+ _disposed = true;
+
+ // 1. 唤醒暂停循环(IsStop 可能卡住后台线程)
+ try
+ {
+ if (_scopedContext != null)
+ {
+ _scopedContext.IsStop = false;
+ _scopedContext.IsTerminate = true;
+ _scopedContext.RunState = "运行";
+ }
+ }
+ catch { }
+ try
+ {
+ if (stepCTS != null && !stepCTS.IsCancellationRequested) stepCTS.Cancel();
+ }
+ catch (ObjectDisposedException) { }
+
+ try
+ {
+ if (errorStepCTS != null && !errorStepCTS.IsCancellationRequested) errorStepCTS.Cancel();
+ }
+ catch (ObjectDisposedException) { }
+
+ tmpParameters.Clear();
+ loopStack.Clear();
+ loopStopwatchStack.Clear();
+ stepStopwatch.Stop();
+ }
+
+
#region 私有类