Пример #1
0
        /// <summary>
        /// Calculates the NextRunAt based on the DateTime.Now property.
        /// </summary>
        /// <param name="isFirstRun">If true, this task will run for the first time. (Is being scheduled.)</param>
        /// <returns>True, if a new run time was calculated.</returns>
        public override bool UpdateNextRunAt(bool isFirstRun)
        {
            var now = DateTime.Now;

            // If this task was never executed, or if it was executed long time ago.
            if (LatstExecutionTime < now.AddMinutes(-(MinutesBetweenRuns * 2)))
            {
                // Long time ago, so schedule it for now.
                LatstExecutionTime = now.AddMinutes(-MinutesBetweenRuns);

                // If the RunAt is set to something in the future, use it.
                if (LatstExecutionTime < RunAt)
                {
                    LatstExecutionTime = RunAt.AddMinutes(-MinutesBetweenRuns);
                }
            }

            var atTime = LatstExecutionTime.AddMinutes(MinutesBetweenRuns);

            // We missed the time, lets do it later.
            while (now > atTime)
            {
                atTime = atTime.AddMinutes(MinutesBetweenRuns);
            }

            NextRunAt = atTime;

            return(true);
        }