|
@@ -10,11 +10,17 @@ namespace Quadarax.Foundation.Core.Thread
|
|
|
private TimeSpan _defaultTimeout;
|
|
private TimeSpan _defaultTimeout;
|
|
|
private long _cntLimit;
|
|
private long _cntLimit;
|
|
|
private Func<IWorkerContext?, Task>? _customIteration;
|
|
private Func<IWorkerContext?, Task>? _customIteration;
|
|
|
|
|
+ private bool _isIterationRunning = false;
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region *** Properties ***
|
|
#region *** Properties ***
|
|
|
public long IterationsLimit { get; set; } = 0;
|
|
public long IterationsLimit { get; set; } = 0;
|
|
|
public TimeSpan IterationsDelayBetween { get; set; } = TimeSpan.Zero;
|
|
public TimeSpan IterationsDelayBetween { get; set; } = TimeSpan.Zero;
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Defines if overlap iteration is allowed. If false, iteration is skipped if previous iteration is not finished.
|
|
|
|
|
+ /// Default value is false.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public bool AllowOverlap { get; set; } = false;
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region *** Constructors ***
|
|
#region *** Constructors ***
|
|
@@ -52,8 +58,15 @@ namespace Quadarax.Foundation.Core.Thread
|
|
|
if (first)
|
|
if (first)
|
|
|
first = false;
|
|
first = false;
|
|
|
else if (IterationsDelayBetween != TimeSpan.Zero)
|
|
else if (IterationsDelayBetween != TimeSpan.Zero)
|
|
|
- System.Threading.Thread.CurrentThread.Join(IterationsDelayBetween);
|
|
|
|
|
|
|
+ await Task.Delay(IterationsDelayBetween);
|
|
|
|
|
+ //System.Threading.Thread.CurrentThread.Join(IterationsDelayBetween);
|
|
|
|
|
|
|
|
|
|
+ if (_isIterationRunning && !AllowOverlap)
|
|
|
|
|
+ {
|
|
|
|
|
+ await Task.Delay(100);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ _isIterationRunning = true;
|
|
|
if (IterationsLimit == 0)
|
|
if (IterationsLimit == 0)
|
|
|
{
|
|
{
|
|
|
if (_customIteration != null)
|
|
if (_customIteration != null)
|
|
@@ -71,6 +84,7 @@ namespace Quadarax.Foundation.Core.Thread
|
|
|
if (_cntLimit > IterationsLimit)
|
|
if (_cntLimit > IterationsLimit)
|
|
|
exit = true;
|
|
exit = true;
|
|
|
}
|
|
}
|
|
|
|
|
+ _isIterationRunning = false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
|
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|