Skip to content

Commit a203f30

Browse files
authored
Merge pull request #200 from N1Ran/master
loop fix
2 parents 0d1598a + f975610 commit a203f30

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

‎Essentials/AutoCommand.cs‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class AutoCommand : ViewModel
3131
private string _name;
3232
private float _triggerRatio;
3333
private double _triggerCount;
34+
private bool _isRunning;
3435

3536
[XmlIgnore]
3637
public bool Completed { get; set; }
@@ -201,24 +202,22 @@ internal async void RunNow()
201202
{
202203
_cTokenSource = new CancellationTokenSource();
203204
var token = _cTokenSource.Token;
204-
205+
_isRunning = true;
205206
await Task.Run(() =>
206207
{
207-
while (!token.IsCancellationRequested)
208+
foreach (var step in Steps)
208209
{
209-
foreach (var step in Steps)
210+
if (token.IsCancellationRequested)
210211
{
211-
if (token.IsCancellationRequested)
212-
{
213-
break;
214-
}
215-
step.RunStep();
216-
Thread.Sleep(step.DelaySpan);
212+
break;
217213
}
214+
step.RunStep();
215+
Thread.Sleep(step.DelaySpan);
218216
}
219217
}, token);
220218

221219
_cTokenSource.Dispose();
220+
_isRunning = false;
222221
}
223222

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

239238
internal bool IsRunning()
240239
{
241-
return _currentStep > 0 || _cTokenSource != null && _cTokenSource?.IsCancellationRequested == false;
240+
return _currentStep > 0 || _isRunning;
242241
}
243242
}
244243

‎Essentials/AutoCommands.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private bool CanRun(AutoCommand command)
4747
case Trigger.Disabled:
4848
return false;
4949
case Trigger.OnStart:
50-
if (command.Completed)break;
50+
if (command.Completed || command.IsRunning())break;
5151
command.Completed = true;
5252
command.RunNow();
5353
break;

0 commit comments

Comments
 (0)