{"record":{"id":"dd97a06ac33e3eae","repo":"dotnet/wpf","slug":"the-dispatcher-failed-to-schedule-a-request-for-processing","errorCode":null,"errorMessage":"The Dispatcher failed to schedule a request for processing.","messagePattern":"The Dispatcher failed to schedule a request for processing\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs","lineNumber":2482,"sourceCode":"\n                // keep the list from growing too large\n                // (although usually it will have only one entry)\n                if (list.Count > 1000)\n                {\n                    // keep the earliest and latest failures\n                    list.RemoveRange(100, list.Count - 200);\n                    // acknowledge the gap\n                    list.Insert(100, \"... entries removed to conserve memory ...\");\n                }\n            }\n\n            // handle the failure, according to app's preference\n            switch (BaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailure)\n            {\n                case BaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailureOptions.Continue:\n                    break;\n                case BaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailureOptions.Throw:\n                    throw new InvalidOperationException(SR.DispatcherRequestProcessingFailed);\n                case BaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailureOptions.Reset:\n                    _postedProcessingType = PROCESS_NONE;\n                    break;\n            }\n        }\n\n        internal void PromoteTimers(int currentTimeInTicks)\n        {\n            try\n            {\n                List<DispatcherTimer> timers = null;\n                long timersVersion = 0;\n\n                lock(_instanceLock)\n                {\n                    if(!_hasShutdownFinished) // Could be a non-dispatcher thread, lock to read\n                    {\n                        if(_dueTimeFound && _dueTimeInTicks - currentTimeInTicks <= 0)","sourceCodeStart":2464,"sourceCodeEnd":2500,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs#L2464-L2500","documentation":"When Dispatcher fails to schedule a background work item for request processing (e.g. the ThreadPool or timer post fails), it consults BaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailure. If the app opted into 'Throw', an InvalidOperationException is raised; 'Continue' swallows it and 'Reset' retries by clearing the posted-processing flag.","triggerScenarios":"QueueUserWorkItem/Timer scheduling fails inside the Dispatcher's request-processing path while BaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailure is set to HandleDispatcherRequestProcessingFailureOptions.Throw.","commonSituations":"Apps that set the compatibility switch for strict failure handling (common in test suites or reliability-sensitive services), especially under thread-pool starvation or when the runtime is shutting down.","solutions":["Change the preference to HandleDispatcherRequestProcessingFailureOptions.Reset or Continue if strict throwing is not required","Set the preference as early as possible (it must be set before the Dispatcher is used, typically at startup)","Investigate why scheduling failed: thread-pool exhaustion, AppDomain/runtime shutdown, or low memory","Retry the Dispatcher operation after the transient condition clears"],"exampleFix":"// before\nBaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailure =\n    BaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailureOptions.Throw;\n// after\nBaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailure =\n    BaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailureOptions.Reset;","handlingStrategy":"try-catch","validationCode":"// verify the compatibility preference at startup\nvar mode = BaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailure;\nDebug.Assert(mode != BaseCompatibilityPreferences.HandleDispatcherRequestProcessingFailureOptions.Throw || Debugger.IsAttached);","typeGuard":null,"tryCatchPattern":"try\n{\n    dispatcher.InvokeAsync(work);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"failed to schedule\"))\n{\n    logger.LogError(ex, \"Dispatcher request processing could not be scheduled\");\n}","preventionTips":["Set HandleDispatcherRequestProcessingFailure once, at app startup, before any Dispatcher use","Prefer Reset for production, Throw only under a debugger/tests","Watch thread-pool health (ThreadPool.ThreadCount, queue lengths)","Avoid scheduling dispatcher work during shutdown"],"tags":["dispatcher","threadpool","scheduling","wpf"],"backgroundTag":"internal-invariant-violation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}