压力测试优化2
This commit is contained in:
@@ -50,13 +50,11 @@ namespace ADP.ViewModels
|
|||||||
set => SetProperty(ref _IsLeftDrawerOpen, value);
|
set => SetProperty(ref _IsLeftDrawerOpen, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 代理属性:动态反映当前被激活的 Scope 状态
|
|
||||||
public TimeSpan RunningTime
|
public TimeSpan RunningTime
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (CurrentContext == null) return TimeSpan.Zero;
|
if (CurrentContext == null) return TimeSpan.Zero;
|
||||||
// 💡 核心:如果当前工位的计时器正在跑,动态累加 SW 当前的时间,否则返回其保存的固定时间值
|
|
||||||
return CurrentContext.SW.IsRunning ? CurrentContext.SW.Elapsed : CurrentContext.RunningTime;
|
return CurrentContext.SW.IsRunning ? CurrentContext.SW.Elapsed : CurrentContext.RunningTime;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
|||||||
@@ -448,7 +448,7 @@
|
|||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Slider Grid.Column="0"
|
<Slider Grid.Column="0"
|
||||||
Minimum="0" Maximum="100"
|
Minimum="100" Maximum="200"
|
||||||
TickFrequency="10" IsSnapToTickEnabled="True"
|
TickFrequency="10" IsSnapToTickEnabled="True"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Value="{Binding SystemConfig.PerformanceLevel}"/>
|
Value="{Binding SystemConfig.PerformanceLevel}"/>
|
||||||
|
|||||||
@@ -22,6 +22,9 @@
|
|||||||
<DataGrid dd:DragDrop.IsDragSource="{Binding Admin}"
|
<DataGrid dd:DragDrop.IsDragSource="{Binding Admin}"
|
||||||
dd:DragDrop.IsDropTarget="{Binding Admin}"
|
dd:DragDrop.IsDropTarget="{Binding Admin}"
|
||||||
dd:DragDrop.UseDefaultDragAdorner="{Binding Admin}"
|
dd:DragDrop.UseDefaultDragAdorner="{Binding Admin}"
|
||||||
|
VirtualizingStackPanel.IsVirtualizing="True"
|
||||||
|
VirtualizingStackPanel.VirtualizationMode="Recycling"
|
||||||
|
VirtualizingStackPanel.ScrollUnit="Pixel"
|
||||||
AutoGenerateColumns="False"
|
AutoGenerateColumns="False"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
CanUserAddRows="False"
|
CanUserAddRows="False"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using static UIShare.UIViewModel.ParameterVM;
|
|||||||
|
|
||||||
namespace UIShare
|
namespace UIShare
|
||||||
{
|
{
|
||||||
public class StepRunning
|
public class StepRunning:IDisposable
|
||||||
{
|
{
|
||||||
private ScopedContext _scopedContext;
|
private ScopedContext _scopedContext;
|
||||||
private SystemConfig _systemConfig;
|
private SystemConfig _systemConfig;
|
||||||
@@ -39,6 +39,9 @@ namespace UIShare
|
|||||||
public CancellationTokenSource errorStepCTS = new();
|
public CancellationTokenSource errorStepCTS = new();
|
||||||
private bool SubSingleStep = false;
|
private bool SubSingleStep = false;
|
||||||
|
|
||||||
|
/// <summary>标记是否已被注销,执行方法据此安全退出</summary>
|
||||||
|
private volatile bool _disposed = false;
|
||||||
|
|
||||||
private Guid TestRoundID;
|
private Guid TestRoundID;
|
||||||
public StepRunning(ScopedContext ScopedContext, SystemConfig systemConfig,IEventAggregator eventAggregator, DeviceManager deviceManager)
|
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)
|
public async Task<bool> ExecuteErrorSteps(ProgramVM program, int depth = 0, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
if (_disposed) return false;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
bool stepSuccess = false;
|
bool stepSuccess = false;
|
||||||
if (depth == 0)
|
if (depth == 0)
|
||||||
@@ -67,7 +71,7 @@ namespace UIShare
|
|||||||
|
|
||||||
while (index < program.ErrorStepCollection.Count)
|
while (index < program.ErrorStepCollection.Count)
|
||||||
{
|
{
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (_disposed || cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -215,6 +219,7 @@ namespace UIShare
|
|||||||
}
|
}
|
||||||
public async Task<bool> ExecuteSteps(ProgramVM program, int depth = 0, CancellationToken cancellationToken = default)
|
public async Task<bool> ExecuteSteps(ProgramVM program, int depth = 0, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
if (_disposed) return false;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
bool stepSuccess = false;
|
bool stepSuccess = false;
|
||||||
if (depth == 0)
|
if (depth == 0)
|
||||||
@@ -232,11 +237,11 @@ namespace UIShare
|
|||||||
|
|
||||||
while (index < program.StepCollection.Count)
|
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;
|
break;
|
||||||
}
|
}
|
||||||
@@ -392,11 +397,12 @@ namespace UIShare
|
|||||||
|
|
||||||
public async Task ExecuteMethodStep(StepVM step, Dictionary<Guid, ParameterVM> parameters, int depth, CancellationToken cancellationToken = default)
|
public async Task ExecuteMethodStep(StepVM step, Dictionary<Guid, ParameterVM> parameters, int depth, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
if (_disposed) return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(_scopedContext.Program.StepCollection.Count>1)
|
if(_scopedContext.Program.StepCollection.Count>1)
|
||||||
_scopedContext.SelectedStep = null;
|
_scopedContext.SelectedStep = null;
|
||||||
await Task.Delay(_systemConfig.PerformanceLevel);
|
await Task.Delay(_systemConfig.PerformanceLevel, cancellationToken);
|
||||||
|
|
||||||
|
|
||||||
// 1. 查找类型
|
// 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 私有类
|
#region 私有类
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user