{"record":{"id":"7ae5a1fbe5208d1a","repo":"aspnetboilerplate/aspnetboilerplate","slug":"period-should-be-set-before-starting-the-timer-7ae5a1","errorCode":null,"errorMessage":"Period should be set before starting the timer!","messagePattern":"Period should be set before starting the timer!","errorType":"exception","errorClass":"AbpException","httpStatus":null,"severity":"error","filePath":"src/Abp/Threading/Timers/AbpTimer.cs","lineNumber":72,"sourceCode":"        /// Creates a new Timer.\n        /// </summary>\n        /// <param name=\"period\">Task period of timer (as milliseconds)</param>\n        /// <param name=\"runOnStart\">Indicates whether timer raises Elapsed event on Start method of Timer for once</param>\n        public AbpTimer(int period, bool runOnStart = false)\n            : this()\n        {\n            Period = period;\n            RunOnStart = runOnStart;\n        }\n\n        /// <summary>\n        /// Starts the timer.\n        /// </summary>\n        public override void Start()\n        {\n            if (Period <= 0)\n            {\n                throw new AbpException(\"Period should be set before starting the timer!\");\n            }\n\n            base.Start();\n\n            _running = true;\n            _taskTimer.Change(RunOnStart ? 0 : Period, Timeout.Infinite);\n        }\n\n        /// <summary>\n        /// Stops the timer.\n        /// </summary>\n        public override void Stop()\n        {\n            lock (_taskTimer)\n            {\n                _running = false;\n                _taskTimer.Change(Timeout.Infinite, Timeout.Infinite);\n            }","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/aspnetboilerplate/aspnetboilerplate/blob/2323c13a152aa0ebfb37af3830f687d7f5b53795/src/Abp/Threading/Timers/AbpTimer.cs#L54-L90","documentation":"The synchronous AbpTimer.Start() checks that the Period property is positive before starting the underlying timer; if Period <= 0 it throws AbpException. The timer cannot schedule callbacks with an invalid period, so the library fails fast. This is a programming/configuration error, not a runtime environment issue.","triggerScenarios":"Calling AbpTimer.Start() when Period was never assigned or assigned 0/negative. Common in custom background jobs or when porting code that previously used a different timer.","commonSituations":"Background worker classes in Abp modules that start timers in PostInitialize without setting Period; configuration values read as 0 because of a missing appSettings key.","solutions":["Assign a positive Period (in milliseconds) before calling Start()","Validate config-sourced period values before constructing the timer","Prefer deriving from AbpWorker / AbpBackgroundWorkerBase which handles timer setup"],"exampleFix":"// before\nvar timer = new AbpTimer { RunOnStart = false };\ntimer.Start(); // throws\n// after\nvar timer = new AbpTimer { Period = 5000, RunOnStart = false };\ntimer.Start();","handlingStrategy":"validation","validationCode":"if (timer.Period <= 0) throw new InvalidOperationException(\"Set Period before starting AbpTimer\");\ntimer.Start();","typeGuard":"bool CanStart(AbpTimer t) => t != null && t.Period > 0;","tryCatchPattern":null,"preventionTips":["Initialize Period together with RunOnStart at construction","Read period from a single validated config source","Prefer AbpBackgroundWorkerBase which encapsulates timer setup"],"tags":["timer","configuration","argument-out-of-range"],"backgroundTag":"missing-required-config-field","analyzedSha":"2323c13a152aa0ebfb37af3830f687d7f5b53795","analyzedAt":"2026-09-08T08:00:50.638Z","contentChangedAt":"2026-09-08T08:00:50.638Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}