stride3d/stride · error · ArgumentOutOfRangeException

TrackingSleepTime must be > 0

Error message

TrackingSleepTime must be > 0

What it means

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.

Solutions

  1. Assign a positive value (e.g. TimeSpan.FromMilliseconds(100) or any value > 0)
  2. Clamp the computed value with Math.Max before assignment
  3. Fix the settings source so a zero/negative default becomes a valid positive interval
  4. If polling should be disabled, use a large sleep time or dispose the tracker instead of 0

Example fix

// before
tracker.TrackingSleepTime = TimeSpan.Zero; // throws
// after
tracker.TrackingSleepTime = TimeSpan.FromMilliseconds(100);
Defensive patterns

Strategy: validation

Validate before calling

var sleep = TimeSpan.FromMilliseconds(settings.SleepMs);
if (sleep <= TimeSpan.Zero)
    sleep = TimeSpan.FromMilliseconds(100);
tracker.TrackingSleepTime = sleep;

Try / catch

try { tracker.TrackingSleepTime = value; }
catch (ArgumentOutOfRangeException)
{
    tracker.TrackingSleepTime = TimeSpan.FromMilliseconds(100); // safe default
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/9dae481dc96a3c09. Report an issue: GitHub.

Appendix: source

Thrown at sources/assets/Stride.Core.Assets/Tracking/AssetSourceTracker.cs:158

            isTrackingPaused = value;
        }
    }

    /// <summary>
    /// Gets or sets the number of ms the file tracker should sleep before checking changes. Default is 1000ms.
    /// </summary>
    /// <value>The tracking sleep time.</value>
    public int TrackingSleepTime
    {
        get
        {
            return trackingSleepTime;
        }
        set
        {
            if (value <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(value), "TrackingSleepTime must be > 0");
            }
            trackingSleepTime = value;
        }
    }

    /// <summary>
    /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
    /// </summary>
    public void Dispose()
    {
        if (isDisposed)
            return;

        isDisposing = true;
        tokenSourceForImportHash.Cancel();
        EnableTracking = false; // Will terminate the thread if running

        DirectoryWatcher?.Dispose();

View on GitHub (pinned to 96fad776d2)