{"record":{"id":"511a876e4f1c6a02","repo":"dotnet/wpf","slug":"error-timeout-1460","errorCode":"ERROR_TIMEOUT (1460)","errorMessage":"TimeoutException","messagePattern":"TimeoutException","errorType":"exception","errorClass":"TimeoutException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Misc.cs","lineNumber":1959,"sourceCode":"        private static void EvaluateSendMessageTimeoutError(int error)\n        {\n            EvaluateSendMessageTimeoutError(error, false);\n        }\n\n        private static void EvaluateSendMessageTimeoutError(int error, bool ignoreTimeout)\n        {\n            // SendMessageTimeout Function\n            // If the function fails or times out, the return value is zero. To get extended error information,\n            // call GetLastError. If GetLastError returns zero, then the function timed out.\n            // NOTE: The GetLastError after a SendMessageTimeout my also be an ERROR_TIMEOUT depending on the\n            // message.\n\n            // 1460 This operation returned because the timeout period expired. ERROR_TIMEOUT\n            if (error == 0 || error == 1460)\n            {\n                if (!ignoreTimeout)\n                {\n                    throw new TimeoutException();\n                }\n            }\n            else\n            {\n                ThrowWin32ExceptionsIfError(error);\n            }\n        }\n\n        private static Rect[] GetTitlebarRectsXP(IntPtr hwnd)\n        {\n            Debug.Assert(System.Environment.OSVersion.Version.Major < 6);\n\n            UnsafeNativeMethods.TITLEBARINFO tiDL;\n            if (!Misc.ProxyGetTitleBarInfo(hwnd, out tiDL))\n            {\n                return null;\n            }\n","sourceCodeStart":1941,"sourceCodeEnd":1977,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Misc.cs#L1941-L1977","documentation":"A Win32 GetLastError value of ERROR_TIMEOUT (1460) after a native operation is deliberately converted to a TimeoutException, unless the caller explicitly opts to ignore timeouts. This signals that a native interop call (typically SendMessageTimeout or a service request) did not complete within its allotted time.","triggerScenarios":"Calling UIAutomation proxy paths that use SendMessageTimeout/native timeouts (e.g. querying a busy window, fetching a property) where the target UI thread is blocked and the timeout elapses.","commonSituations":"Target application's UI thread hung (long synchronous work, modal wait); automating a window in a different session or elevated process that cannot respond; slow startup of the automated app.","solutions":["Investigate and fix the hang in the target application's UI thread (the real fix).","Retry the operation after a short delay if the target is expected to become responsive.","Increase the native timeout used in the call (e.g. SendMessageTimeout parameters) if the operation is legitimately slow.","Catch TimeoutException and treat the target as unresponsive: kill/restart or surface a diagnostic."],"exampleFix":"// before\nvar value = busyElement.GetCurrentPropertyValue(ValuePattern.ValueProperty); // throws TimeoutException\n\n// after\ntry\n{\n    var value = busyElement.GetCurrentPropertyValue(ValuePattern.ValueProperty);\n}\ncatch (TimeoutException)\n{\n    logger.Warn(\"Target window unresponsive; retrying once after 2s\");\n    Thread.Sleep(2000);\n    var value = busyElement.GetCurrentPropertyValue(ValuePattern.ValueProperty);\n}","handlingStrategy":"retry","validationCode":"if (!responseWindow.Responding)\n    throw new SkipScenarioException($\"Window '{responseWindow.Title}' is hung\");","typeGuard":"static bool IsResponsive(IntPtr hwnd)\n{\n    // smoke-test the target UI thread with a fast timeout before real calls\n    var ok = SendMessageTimeout(hwnd, WM_NULL, IntPtr.Zero, IntPtr.Zero,\n        SMTO_ABORTIFHUNG, 1000, out _);\n    return ok != IntPtr.Zero;\n}","tryCatchPattern":"const int MaxAttempts = 3;\nfor (int i = 1; ; i++)\n{\n    try { result = element.GetCurrentPropertyValue(prop); break; }\n    catch (TimeoutException) when (i < MaxAttempts) { Thread.Sleep(500 * i); }\n}","preventionTips":["Check Process.Responding before querying elements of the target app.","Diagnose and fix UI-thread hangs in the automated application.","Use bounded retry with backoff for property queries.","Avoid automating windows in different/elevated sessions that cannot answer messages."],"tags":["timeout","uiautomation","native-interop","hung-ui"],"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"}