Skip to content

Commit 5878c87

Browse files
committed
v6.4.1: fix #12 - task intervals should be less that int.MaxValue milliseconds (~24d 20H)
1 parent 134212b commit 5878c87

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/RecurrentTasks/RecurrentTasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageLicenseUrl></PackageLicenseUrl>
1212
<RepositoryType>git</RepositoryType>
1313
<RepositoryUrl>https://github.com/justdmitry/RecurrentTasks.git</RepositoryUrl>
14-
<Version>6.4.0</Version>
14+
<Version>6.4.1</Version>
1515
<Description>RecurrentTasks for .NET allows you to run simple recurrent background tasks with specific intervals, without complex frameworks, persistance, etc...</Description>
1616
<Authors>just_dmitry</Authors>
1717
<Company />

src/RecurrentTasks/TaskOptions.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
public class TaskOptions
88
{
9+
/// <summary>
10+
/// Maximum allowed <see cref="Interval"/> and <see cref="FirstRunDelay"/> values.
11+
/// </summary>
12+
public static readonly TimeSpan MaxInterval = TimeSpan.FromMilliseconds(int.MaxValue);
13+
14+
private TimeSpan interval;
15+
private TimeSpan firstRunDelay = TimeSpan.FromSeconds(new Random().Next(10, 30));
16+
917
/// <summary>
1018
/// If non-null, current thread culture will be set to this value before <see cref="IRunnable.RunAsync"/> is called
1119
/// </summary>
@@ -17,15 +25,48 @@ public class TaskOptions
1725
public bool AutoStart { get; set; } = true;
1826

1927
/// <summary>
20-
/// Task run interval
28+
/// Task run interval.
2129
/// </summary>
22-
public TimeSpan Interval { get; set; }
30+
public TimeSpan Interval
31+
{
32+
get
33+
{
34+
return interval;
35+
}
36+
37+
set
38+
{
39+
if (value > MaxInterval)
40+
{
41+
throw new ArgumentOutOfRangeException(nameof(Interval), "Must be less than Int32.MaxValue milliseconds (approx. 24 days 20 hours)");
42+
}
43+
44+
interval = value;
45+
}
46+
}
2347

2448
/// <summary>
2549
/// First run delay (to prevent app freeze during startup due to many tasks initialization).
2650
/// Default is random value from 10 to 30 seconds.
2751
/// </summary>
28-
public TimeSpan FirstRunDelay { get; set; } = TimeSpan.FromSeconds(new Random().Next(10, 30));
52+
public TimeSpan FirstRunDelay
53+
{
54+
get
55+
{
56+
return interval;
57+
}
58+
59+
set
60+
{
61+
if (value > MaxInterval)
62+
{
63+
throw new ArgumentOutOfRangeException(nameof(FirstRunDelay), "Must be less than Int32.MaxValue milliseconds (approx. 24 days 20 hours)");
64+
}
65+
66+
interval = value;
67+
}
68+
}
69+
2970

3071
/// <summary>
3172
/// Return <b>false</b> to cancel/skip task run

0 commit comments

Comments
 (0)