Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
loop fix
  • Loading branch information
N1Ran committed Feb 6, 2022
commit f9756101bf52c736477dfdcd3090ac96e32f3967
19 changes: 9 additions & 10 deletions Essentials/AutoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class AutoCommand : ViewModel
private string _name;
private float _triggerRatio;
private double _triggerCount;
private bool _isRunning;

[XmlIgnore]
public bool Completed { get; set; }
Expand Down Expand Up @@ -201,24 +202,22 @@ internal async void RunNow()
{
_cTokenSource = new CancellationTokenSource();
var token = _cTokenSource.Token;

_isRunning = true;
await Task.Run(() =>
{
while (!token.IsCancellationRequested)
foreach (var step in Steps)
{
foreach (var step in Steps)
if (token.IsCancellationRequested)
{
if (token.IsCancellationRequested)
{
break;
}
step.RunStep();
Thread.Sleep(step.DelaySpan);
break;
}
step.RunStep();
Thread.Sleep(step.DelaySpan);
}
}, token);

_cTokenSource.Dispose();
_isRunning = false;
}

internal void Cancel()
Expand All @@ -238,7 +237,7 @@ public override string ToString()

internal bool IsRunning()
{
return _currentStep > 0 || _cTokenSource != null && _cTokenSource?.IsCancellationRequested == false;
return _currentStep > 0 || _isRunning;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Essentials/AutoCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private bool CanRun(AutoCommand command)
case Trigger.Disabled:
return false;
case Trigger.OnStart:
if (command.Completed)break;
if (command.Completed || command.IsRunning())break;
command.Completed = true;
command.RunNow();
break;
Expand Down