dotnet/wpf · error · TimeoutException

SR.AutomationTimeout

Error message

SR.AutomationTimeout

What it means

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.

Solutions

  1. Keep the UI thread responsive — move long work off the dispatcher thread (async/Task.Run).
  2. In the UIA client, catch TimeoutException and retry once after the app becomes idle.
  3. Break UI-thread deadlocks: ensure the app never blocks on the automation client while the client blocks on the app.
  4. Raise the automation request timeout in the client framework if legitimately long operations are expected.

Example fix

// before (app code blocking UI thread)
Thread.Sleep(10000); // UIA calls time out
// after
await Task.Delay(10000); // keep dispatcher free to service automation calls
Defensive patterns

Strategy: retry

Validate before calling

// before automating, confirm the UI thread is responsive
if (!window.Dispatcher.CheckAccess() && window.Dispatcher.HasShutdownStarted) return;

Type guard

bool CanInvoke(Dispatcher d) => d != null && !d.HasShutdownStarted;

Try / catch

try
{
    element.GetCurrentPattern(InvokePattern.Pattern);
}
catch (TimeoutException)
{
    WaitForInputIdle(process, TimeSpan.FromSeconds(5));
    // retry once
}

Prevention

When it happens

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

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

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/93e890101f3075f1. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/ElementUtil.cs:231

                
            if(completed)
            {
                if(remoteException != null)
                {
                    throw remoteException;
                }
            }
            else
            {
                bool dispatcherInShutdown = dispatcher.HasShutdownStarted;

                if(dispatcherInShutdown)
                {
                    throw new InvalidOperationException(SR.AutomationDispatcherShutdown);
                }
                else
                {
                    throw new TimeoutException(SR.AutomationTimeout);
                }
            }
            
            return retVal;
}

        #endregion Internal Methods

        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        // Potential enhancement: Consider Visual3Ds in this walk?
        //      Does this walk need to continue through the Visual3D tree once
        //      we have UIElement3D?
        private static Visual FindVisibleSibling ( Visual parent, int start, bool searchForwards)

View on GitHub (pinned to 81131a70a4)