InvokePattern.Invoke抛出Win32Exception“热键已经注册” [英] InvokePattern.Invoke throwing Win32Exception "Hot key is already registered"
问题描述
您好,
我目前正在使用UIAutomation API来处理Javascript对话框。 在大多数情况下,这已经很有效,但我经常得到这个随机异常,我不知道如何解决/修复它。
例外:热键已经注册
类型:System.ComponentModel.Win32Exception
Stack: 在MS.Internal.AutomationProxies.Misc.ThrowWin32ExceptionsIfError(Int32 errorCode)
在MS.Internal.AutomationProxies.Misc.SetFocus(IntPtr hwnd)
在MS.Internal.AutomationProxies.WindowsButton.Invoke()
在MS.Internal.AutomationProxies.WindowsButton.System.Windows.Automation.Provider.IInvokeProvider.Invoke()
在System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode,IntPtr errorInfo)
在System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
在MS.Internal.Automation.UiaCoreApi.CheckError(Int32 hr)
在System.Windows.Automation.InvokePattern.Invoke()
这是我用来处理对话框的代码。
var okButton = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty," 1" ));
var invokePattern = okButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
invokePattern.Invoke();
如果可以保证包含被调用按钮的窗口是前景在调用按钮之前的窗口,那可能会使问题消失。如果没有,您是否同时运行多个脚本?如果
如此,那么尝试序列化脚本的执行以查看是否会导致问题消失可能会很有趣。
谢谢,
盖
Hello,
I am currently using the UIAutomation API to handle Javascript dialogs. For the most part this has worked great but every so often I get this random Exception and I'm not sure how to work around/fix it.
Exception:Hot key is already registered
Type:System.ComponentModel.Win32Exception
Stack: at MS.Internal.AutomationProxies.Misc.ThrowWin32ExceptionsIfError(Int32 errorCode)
at MS.Internal.AutomationProxies.Misc.SetFocus(IntPtr hwnd)
at MS.Internal.AutomationProxies.WindowsButton.Invoke()
at MS.Internal.AutomationProxies.WindowsButton.System.Windows.Automation.Provider.IInvokeProvider.Invoke()
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at MS.Internal.Automation.UiaCoreApi.CheckError(Int32 hr)
at System.Windows.Automation.InvokePattern.Invoke()
This is the code that I am using to handle the dialog.
var okButton = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "1")); var invokePattern = okButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; invokePattern.Invoke();
Hi, if it's possible to guarantee that the window containing the button that's being invoked is the foreground window before you invoke the button, then that might make the problem go away. If not, do you have multiple scripts running at the same time? If so, it might be interesting to try serializing the execution of the scripts to see if that makes the problem go away.
Thanks,
Guy
这篇关于InvokePattern.Invoke抛出Win32Exception“热键已经注册”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!