压力测试优化2

This commit is contained in:
hsc
2026-06-26 10:04:57 +08:00
parent f83c93fcf9
commit 52edf16176
4 changed files with 51 additions and 10 deletions

View File

@@ -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

View File

@@ -448,7 +448,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Slider Grid.Column="0"
Minimum="0" Maximum="100"
Minimum="100" Maximum="200"
TickFrequency="10" IsSnapToTickEnabled="True"
VerticalAlignment="Center"
Value="{Binding SystemConfig.PerformanceLevel}"/>

View File

@@ -22,6 +22,9 @@
<DataGrid dd:DragDrop.IsDragSource="{Binding Admin}"
dd:DragDrop.IsDropTarget="{Binding Admin}"
dd:DragDrop.UseDefaultDragAdorner="{Binding Admin}"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling"
VirtualizingStackPanel.ScrollUnit="Pixel"
AutoGenerateColumns="False"
Background="Transparent"
CanUserAddRows="False"

View File

@@ -18,7 +18,7 @@ using static UIShare.UIViewModel.ParameterVM;
namespace UIShare
{
public class StepRunning
public class StepRunning:IDisposable
{
private ScopedContext _scopedContext;
private SystemConfig _systemConfig;
@@ -39,6 +39,9 @@ namespace UIShare
public CancellationTokenSource errorStepCTS = new();
private bool SubSingleStep = false;
/// <summary>标记是否已被注销,执行方法据此安全退出</summary>
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<bool> 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<bool> 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<Guid, ParameterVM> 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