本文介绍了InvokePattern.Invoke抛出Win32Exception“热键已经注册”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好, 


我目前正在使用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();
解决方案


这篇关于InvokePattern.Invoke抛出Win32Exception“热键已经注册”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 20:05