{"record":{"id":"93e890101f3075f1","repo":"dotnet/wpf","slug":"sr-automationtimeout","errorCode":null,"errorMessage":"SR.AutomationTimeout","messagePattern":"SR\\.AutomationTimeout","errorType":"exception","errorClass":"TimeoutException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/ElementUtil.cs","lineNumber":231,"sourceCode":"                \n            if(completed)\n            {\n                if(remoteException != null)\n                {\n                    throw remoteException;\n                }\n            }\n            else\n            {\n                bool dispatcherInShutdown = dispatcher.HasShutdownStarted;\n\n                if(dispatcherInShutdown)\n                {\n                    throw new InvalidOperationException(SR.AutomationDispatcherShutdown);\n                }\n                else\n                {\n                    throw new TimeoutException(SR.AutomationTimeout);\n                }\n            }\n            \n            return retVal;\n}\n\n        #endregion Internal Methods\n\n        //------------------------------------------------------\n        //\n        //  Private Methods\n        //\n        //------------------------------------------------------\n\n        // Potential enhancement: Consider Visual3Ds in this walk?\n        //      Does this walk need to continue through the Visual3D tree once\n        //      we have UIElement3D?\n        private static Visual FindVisibleSibling ( Visual parent, int start, bool searchForwards)","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/ElementUtil.cs#L213-L249","documentation":"ElementUtil.Invoke waits for the peer's dispatcher to execute the automation call within a timeout. If the dispatcher is not shutting down but the operation still did not complete in time, the library throws TimeoutException with SR.AutomationTimeout, meaning the UI thread never serviced the automation request.","triggerScenarios":"Calling any automation peer API routed through ElementUtil.Invoke while the target UI thread is blocked (long synchronous work, modal wait, Sleep, debugger break) so the queued dispatcher operation exceeds the timeout.","commonSituations":"UI Automation against an app whose UI thread is busy or hung; automated tests running during long layout/render work or synchronous waits; deadlock caused by the UI thread waiting on the automation client.","solutions":["Keep the UI thread responsive — move long work off the dispatcher thread (async/Task.Run).","In the UIA client, catch TimeoutException and retry once after the app becomes idle.","Break UI-thread deadlocks: ensure the app never blocks on the automation client while the client blocks on the app.","Raise the automation request timeout in the client framework if legitimately long operations are expected."],"exampleFix":"// before (app code blocking UI thread)\nThread.Sleep(10000); // UIA calls time out\n// after\nawait Task.Delay(10000); // keep dispatcher free to service automation calls","handlingStrategy":"retry","validationCode":"// before automating, confirm the UI thread is responsive\nif (!window.Dispatcher.CheckAccess() && window.Dispatcher.HasShutdownStarted) return;","typeGuard":"bool CanInvoke(Dispatcher d) => d != null && !d.HasShutdownStarted;","tryCatchPattern":"try\n{\n    element.GetCurrentPattern(InvokePattern.Pattern);\n}\ncatch (TimeoutException)\n{\n    WaitForInputIdle(process, TimeSpan.FromSeconds(5));\n    // retry once\n}","preventionTips":["Keep the UI thread free of long-running synchronous work","Move heavy computation off the dispatcher (async/Task.Run)","Avoid debugging breaks or Sleep calls while UIA clients are attached","Retry automation calls after WaitForInputIdle"],"tags":["wpf","ui-automation","timeout","dispatcher"],"backgroundTag":"request-timeout","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"}