{"record":{"id":"e078286ca190e300","repo":"cefsharp/CefSharp","slug":"maxdegreeofparallelism","errorCode":null,"errorMessage":"maxDegreeOfParallelism","messagePattern":"maxDegreeOfParallelism","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"CefSharp/Internals/Tasks/LimitedConcurrencyLevelTaskScheduler.cs","lineNumber":42,"sourceCode":"        [ThreadStatic]\n        private static bool _currentThreadIsProcessingItems;\n        /// <summary>The list of tasks to be executed.</summary>\n        private readonly LinkedList<Task> _tasks = new LinkedList<Task>(); // protected by lock(_tasks)\n        /// <summary>The maximum concurrency level allowed by this scheduler.</summary>\n        private readonly int _maxDegreeOfParallelism;\n        /// <summary>Whether the scheduler is currently processing work items.</summary>\n        private int _delegatesQueuedOrRunning = 0; // protected by lock(_tasks)\n\n        /// <summary>\n        /// Initializes an instance of the LimitedConcurrencyLevelTaskScheduler class with the\n        /// specified degree of parallelism.\n        /// </summary>\n        /// <param name=\"maxDegreeOfParallelism\">The maximum degree of parallelism provided by this scheduler.</param>\n        public LimitedConcurrencyLevelTaskScheduler(int maxDegreeOfParallelism)\n        {\n            if (maxDegreeOfParallelism < 1)\n            {\n                throw new ArgumentOutOfRangeException(\"maxDegreeOfParallelism\");\n            }\n\n            _maxDegreeOfParallelism = maxDegreeOfParallelism;\n        }\n\n        /// <summary>Queues a task to the scheduler.</summary>\n        /// <param name=\"task\">The task to be queued.</param>\n        protected sealed override void QueueTask(Task task)\n        {\n            // Add the task to the list of tasks to be processed.  If there aren't enough\n            // delegates currently queued or running to process tasks, schedule another.\n            lock (_tasks)\n            {\n                _tasks.AddLast(task);\n                if (_delegatesQueuedOrRunning < _maxDegreeOfParallelism)\n                {\n                    ++_delegatesQueuedOrRunning;\n                    NotifyThreadPoolOfPendingWork();","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Internals/Tasks/LimitedConcurrencyLevelTaskScheduler.cs#L24-L60","documentation":"Thrown by the LimitedConcurrencyLevelTaskScheduler constructor when maxDegreeOfParallelism is less than 1. The scheduler enforces an upper bound on concurrent task execution and a bound of zero or negative is meaningless, so it rejects it immediately with ArgumentOutOfRangeException.","triggerScenarios":"Constructing new LimitedConcurrencyLevelTaskScheduler(0) or a negative value; computing the degree from configuration/Environment.ProcessorCount and getting 0 (e.g. on a constrained host or a config typo).","commonSituations":"Config-driven parallelism defaulting to 0; subtracting from ProcessorCount and going negative; shared scheduler factory misconfigured.","solutions":["Pass a value >= 1 (commonly Environment.ProcessorCount or a fixed sane default).","Clamp the computed value: Math.Max(1, configured) before constructing.","Validate configuration at startup so a bad value fails early with a clear message.","Unit-test the scheduler construction path with boundary inputs."],"exampleFix":"// before\nvar sched = new LimitedConcurrencyLevelTaskScheduler(configuredDegree); // 0 -> throws\n\n// after\nvar degree = Math.Max(1, configuredDegree);\nvar sched = new LimitedConcurrencyLevelTaskScheduler(degree);","handlingStrategy":"validation","validationCode":"var degree = Math.Max(1, configuredDegree);\nvar scheduler = new LimitedConcurrencyLevelTaskScheduler(degree);","typeGuard":null,"tryCatchPattern":"try { var s = new LimitedConcurrencyLevelTaskScheduler(n); }\ncatch (ArgumentOutOfRangeException) { var s = new LimitedConcurrencyLevelTaskScheduler(1); }","preventionTips":["Clamp the degree with Math.Max(1, value).","Validate configuration at startup.","Default to Environment.ProcessorCount when config is absent."],"tags":["cefsharp","task-scheduler","argument-validation","concurrency"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}