{"record":{"id":"9dae481dc96a3c09","repo":"stride3d/stride","slug":"trackingsleeptime-must-be-0","errorCode":null,"errorMessage":"TrackingSleepTime must be > 0","messagePattern":"TrackingSleepTime must be > 0","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/Tracking/AssetSourceTracker.cs","lineNumber":158,"sourceCode":"            isTrackingPaused = value;\n        }\n    }\n\n    /// <summary>\n    /// Gets or sets the number of ms the file tracker should sleep before checking changes. Default is 1000ms.\n    /// </summary>\n    /// <value>The tracking sleep time.</value>\n    public int TrackingSleepTime\n    {\n        get\n        {\n            return trackingSleepTime;\n        }\n        set\n        {\n            if (value <= 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(value), \"TrackingSleepTime must be > 0\");\n            }\n            trackingSleepTime = value;\n        }\n    }\n\n    /// <summary>\n    /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.\n    /// </summary>\n    public void Dispose()\n    {\n        if (isDisposed)\n            return;\n\n        isDisposing = true;\n        tokenSourceForImportHash.Cancel();\n        EnableTracking = false; // Will terminate the thread if running\n\n        DirectoryWatcher?.Dispose();","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Tracking/AssetSourceTracker.cs#L140-L176","documentation":"AssetSourceTracker.TrackingSleepTime controls the polling sleep interval of the file-event thread; the setter validates it must be strictly greater than zero. A zero or negative value would make the watcher thread spin or misbehave, so the library throws ArgumentOutOfRangeException with the parameter name.","triggerScenarios":"Assigning tracker.TrackingSleepTime = 0 or a negative TimeSpan/int, typically computed from a config value or elapsed-time calculation; accidentally assigning a TimeSpan-derived value without converting units.","commonSituations":"Loading the sleep time from an editor settings file that stores 0 as a 'disabled' sentinel; unit tests injecting 0 to make polling instant; culture/unit mistakes (seconds vs milliseconds).","solutions":["Assign a positive value (e.g. TimeSpan.FromMilliseconds(100) or any value > 0)","Clamp the computed value with Math.Max before assignment","Fix the settings source so a zero/negative default becomes a valid positive interval","If polling should be disabled, use a large sleep time or dispose the tracker instead of 0"],"exampleFix":"// before\ntracker.TrackingSleepTime = TimeSpan.Zero; // throws\n// after\ntracker.TrackingSleepTime = TimeSpan.FromMilliseconds(100);","handlingStrategy":"validation","validationCode":"var sleep = TimeSpan.FromMilliseconds(settings.SleepMs);\nif (sleep <= TimeSpan.Zero)\n    sleep = TimeSpan.FromMilliseconds(100);\ntracker.TrackingSleepTime = sleep;","typeGuard":null,"tryCatchPattern":"try { tracker.TrackingSleepTime = value; }\ncatch (ArgumentOutOfRangeException)\n{\n    tracker.TrackingSleepTime = TimeSpan.FromMilliseconds(100); // safe default\n}","preventionTips":["Clamp configured sleep values with Math.Max(1, value) before assignment","Never use 0 as a 'disabled' sentinel for this property","Unit-test settings parsing so zero/negative values are converted early","Keep units consistent (TimeSpan everywhere) to avoid ms/s mistakes"],"tags":["csharp","argumentoutofrangeexception","configuration","asset-tracking"],"backgroundTag":"value-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}