{"record":{"id":"bad25f32e21ad9b1","repo":"stride3d/stride","slug":"maximumconcurrencylevel","errorCode":null,"errorMessage":"maximumConcurrencyLevel","messagePattern":"maximumConcurrencyLevel","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Effects/Compiler/EffectPriorityScheduler.cs","lineNumber":31,"sourceCode":"    /// A <see cref=\"TaskScheduler\"/> with control over concurrency and priority, useful with <see cref=\"EffectCompilerCache\"/>.\n    /// </summary>\n    public class EffectPriorityScheduler : TaskScheduler, IDisposable\n    {\n        private static object lockObject = new object();\n        private ThreadPriority threadPriority;\n        private Thread[] threads;\n        private readonly int maximumConcurrencyLevel;\n        private readonly PriorityQueue<QueuedTask> taskPriorityQueue;\n        private readonly System.Collections.Generic.SortedList<int, PriorityGroupScheduler> priorityGroups = new System.Collections.Generic.SortedList<int, PriorityGroupScheduler>();\n        private readonly AutoResetEvent notifyQueuedTaskEvent = new AutoResetEvent(false);\n        private readonly AutoResetEvent notifyHighPriorityQueuedTaskEvent = new AutoResetEvent(false);\n        private readonly ManualResetEvent notifyThreadExitEvent = new ManualResetEvent(false);\n        private bool threadShouldExit;\n\n        public EffectPriorityScheduler(ThreadPriority threadPriority, int maximumConcurrencyLevel)\n        {\n            if (maximumConcurrencyLevel == 0)\n                throw new ArgumentOutOfRangeException(\"maximumConcurrencyLevel\");\n\n            this.taskPriorityQueue = new PriorityQueue<QueuedTask>(new TaskPriorityComparer());\n\n            this.threadPriority = threadPriority;\n            this.maximumConcurrencyLevel = maximumConcurrencyLevel;\n        }\n\n        public int QueuedTaskCount { get { return taskPriorityQueue.Count; } }\n\n        /// <inheritdoc/>\n        public override int MaximumConcurrencyLevel\n        {\n            get { return maximumConcurrencyLevel; }\n        }\n\n        /// <inheritdoc/>\n        protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)\n        {","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Effects/Compiler/EffectPriorityScheduler.cs#L13-L49","documentation":"EffectPriorityScheduler schedules shader-compile tasks on dedicated threads with a bounded concurrency level. Zero is invalid (would mean no worker threads), so the constructor throws ArgumentOutOfRangeException for maximumConcurrencyLevel == 0. Note negative values are not rejected by this guard.","triggerScenarios":"new EffectPriorityScheduler(threadPriority, 0) — passing a zero concurrency level, e.g. from a config value of 0 or Environment.ProcessorCount miscomputation.","commonSituations":"Config files with maxConcurrency=0 meant as 'unlimited'; CPU-count detection returning 0 in restricted containers.","solutions":["Pass at least 1 for maximumConcurrencyLevel, or use Environment.ProcessorCount.","Clamp the configured value before constructing: Math.Max(1, configured).","Fix config/container settings that resolve to 0."],"exampleFix":"// before\nvar scheduler = new EffectPriorityScheduler(ThreadPriority.Normal, config.MaxConcurrency);\n// after\nvar scheduler = new EffectPriorityScheduler(ThreadPriority.Normal, Math.Max(1, config.MaxConcurrency));","handlingStrategy":"validation","validationCode":"if (maximumConcurrencyLevel < 1) throw new InvalidOperationException($\"maximumConcurrencyLevel must be >= 1, got {maximumConcurrencyLevel}\");","typeGuard":"null","tryCatchPattern":"try { var scheduler = new EffectPriorityScheduler(priority, level); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"maximumConcurrencyLevel\") { level = Math.Max(1, level); }","preventionTips":["Clamp configured concurrency with Math.Max(1, value)","Avoid literal 0 in scheduler configs","Use Environment.ProcessorCount as default"],"tags":["argument-out-of-range","scheduling","configuration"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}