From b2d29387604b158b85a785d4b3cb1d4b03419c04 Mon Sep 17 00:00:00 2001 From: Maikel Veen Date: Fri, 23 Oct 2020 18:02:52 +0200 Subject: [PATCH] Add overloaded method for RecurringTaskBase --- .../Scheduling/RecurringTaskBase.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Scheduling/RecurringTaskBase.cs b/src/Umbraco.Web/Scheduling/RecurringTaskBase.cs index 58df54a07e..4544711946 100644 --- a/src/Umbraco.Web/Scheduling/RecurringTaskBase.cs +++ b/src/Umbraco.Web/Scheduling/RecurringTaskBase.cs @@ -15,9 +15,29 @@ namespace Umbraco.Web.Scheduling public abstract class RecurringTaskBase : LatchedBackgroundTaskBase { private readonly IBackgroundTaskRunner _runner; - private readonly int _periodMilliseconds; + private readonly long _periodMilliseconds; private readonly Timer _timer; + /// + /// Initializes a new instance of the class. + /// + /// The task runner. + /// The delay. + /// The period. + /// The task will repeat itself periodically. Use this constructor to create a new task. + protected RecurringTaskBase(IBackgroundTaskRunner runner, long delayMilliseconds, long periodMilliseconds) + { + _runner = runner; + _periodMilliseconds = periodMilliseconds; + + // note + // must use the single-parameter constructor on Timer to avoid it from being GC'd + // read http://stackoverflow.com/questions/4962172/why-does-a-system-timers-timer-survive-gc-but-not-system-threading-timer + + _timer = new Timer(_ => Release()); + _timer.Change(delayMilliseconds, 0); + } + /// /// Initializes a new instance of the class. ///