{"record":{"id":"12ddf0e653d14067","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-the-range-of-valid-values-12ddf0","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'period')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'period'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.cs","lineNumber":132,"sourceCode":"            //\n            return new StopwatchImpl();\n        }\n\n        /// <summary>\n        /// Schedules a periodic piece of work, using a System.Threading.Timer object.\n        /// </summary>\n        /// <typeparam name=\"TState\">The type of the state passed to the scheduled action.</typeparam>\n        /// <param name=\"state\">Initial state passed to the action upon the first iteration.</param>\n        /// <param name=\"period\">Period for running the work periodically.</param>\n        /// <param name=\"action\">Action to be executed, potentially updating the state.</param>\n        /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"action\"/> is <c>null</c>.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"period\"/> is less than zero.</exception>\n        public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)\n        {\n            if (period < TimeSpan.Zero)\n            {\n                throw new ArgumentOutOfRangeException(nameof(period));\n            }\n\n            if (action == null)\n            {\n                throw new ArgumentNullException(nameof(action));\n            }\n\n            if (period == TimeSpan.Zero)\n            {\n                return new FastPeriodicTimer<TState>(state, action);\n            }\n\n            return new PeriodicTimer<TState>(state, period, action);\n        }\n\n        private sealed class FastPeriodicTimer<TState> : IDisposable\n        {\n            private TState _state;","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.cs#L114-L150","documentation":"ThreadPoolScheduler.SchedulePeriodic throws ArgumentOutOfRangeException when the period is negative (less than TimeSpan.Zero). Like the TaskPool variant, a strictly negative periodic interval is rejected as an invalid value before any other work is done.","triggerScenarios":"Calling scheduler.SchedulePeriodic(state, TimeSpan.FromSeconds(-1), action) or any computed negative duration.","commonSituations":"Reversed subtraction for the interval, misparsed config values ('-5s'), or unit conversion mistakes when migrating from milliseconds/int APIs.","solutions":["Pass a zero or positive TimeSpan.","Clamp negative computed periods to TimeSpan.Zero before the call.","Fix the computation/parsing that produced the negative value."],"exampleFix":"// before\nvar period = TimeSpan.FromMilliseconds(intervalMs); // intervalMs = -250\nscheduler.SchedulePeriodic(state, period, next => next);\n// after\nvar period = TimeSpan.FromMilliseconds(Math.Max(0, intervalMs));\nscheduler.SchedulePeriodic(state, period, next => next);","handlingStrategy":"validation","validationCode":"if (period < TimeSpan.Zero) throw new InvalidOperationException($\"Negative period {period}\");\nscheduler.SchedulePeriodic(state, period, action);","typeGuard":null,"tryCatchPattern":"try { scheduler.SchedulePeriodic(state, period, action); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"period\") { log.LogError(\"Period must be non-negative, got {Period}\", period); }","preventionTips":["Sanitize durations parsed from config/env before scheduling.","Use checked subtraction and guard reversed time ranges."],"tags":["rx","scheduler","argument-out-of-range","timespan"],"backgroundTag":"argument-out-of-range","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}