Skip to content

Commit

Permalink
v6.4.1: fix #12 - task intervals should be less that int.MaxValue mil…
Browse files Browse the repository at this point in the history
…liseconds (~24d 20H)
  • Loading branch information
justdmitry committed Aug 11, 2021
1 parent 134212b commit 5878c87
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/RecurrentTasks/RecurrentTasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageLicenseUrl></PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/justdmitry/RecurrentTasks.git</RepositoryUrl>
<Version>6.4.0</Version>
<Version>6.4.1</Version>
<Description>RecurrentTasks for .NET allows you to run simple recurrent background tasks with specific intervals, without complex frameworks, persistance, etc...</Description>
<Authors>just_dmitry</Authors>
<Company />
Expand Down
47 changes: 44 additions & 3 deletions src/RecurrentTasks/TaskOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

public class TaskOptions
{
/// <summary>
/// Maximum allowed <see cref="Interval"/> and <see cref="FirstRunDelay"/> values.
/// </summary>
public static readonly TimeSpan MaxInterval = TimeSpan.FromMilliseconds(int.MaxValue);

private TimeSpan interval;
private TimeSpan firstRunDelay = TimeSpan.FromSeconds(new Random().Next(10, 30));

/// <summary>
/// If non-null, current thread culture will be set to this value before <see cref="IRunnable.RunAsync"/> is called
/// </summary>
Expand All @@ -17,15 +25,48 @@ public class TaskOptions
public bool AutoStart { get; set; } = true;

/// <summary>
/// Task run interval
/// Task run interval.
/// </summary>
public TimeSpan Interval { get; set; }
public TimeSpan Interval
{
get
{
return interval;
}

set
{
if (value > MaxInterval)
{
throw new ArgumentOutOfRangeException(nameof(Interval), "Must be less than Int32.MaxValue milliseconds (approx. 24 days 20 hours)");
}

interval = value;
}
}

/// <summary>
/// First run delay (to prevent app freeze during startup due to many tasks initialization).
/// Default is random value from 10 to 30 seconds.
/// </summary>
public TimeSpan FirstRunDelay { get; set; } = TimeSpan.FromSeconds(new Random().Next(10, 30));
public TimeSpan FirstRunDelay
{
get
{
return interval;
}

set
{
if (value > MaxInterval)
{
throw new ArgumentOutOfRangeException(nameof(FirstRunDelay), "Must be less than Int32.MaxValue milliseconds (approx. 24 days 20 hours)");
}

interval = value;
}
}


/// <summary>
/// Return <b>false</b> to cancel/skip task run
Expand Down

0 comments on commit 5878c87

Please sign in to comment.