小编o_w*_*man的帖子

一段时间后,UI自动化事件在监视应用程序后停止接收,然后在一段时间后重新启动

我们正在使用Microsoft的UIAutomation框架来开发一个监视特定应用程序事件的客户端,并以不同的方式响应它们.我们已经开始使用该框架的托管版本,但由于延迟问题,转移到UIACOMWrapper包含的本机版本.在我们(大规模)WPF应用程序中出现更多性能问题后,我们决定将其移至单独的终端应用程序(通过UDP将事件传输到我们的WPF应用程序),这似乎解决了所有性能问题.唯一的问题是,似乎每隔几分钟,TabSelection,StructureChanged,WindowOpened和WindowClosed的事件就会被捕获几分钟.令人惊讶的是,当发生这种情况时,仍会接收和处理PropertyChanged事件.我将发布我们的事件监视器的相关代码,但这可能无关紧要,因为我们在使用Microsoft自己的AccEvent实用程序时已经看到类似的行为.我不能发布受监控应用程序的代码,因为它是专有的和保密的,我可以说它是一个承载WPF窗口的WinForms应用程序,也非常庞大.有没有人在使用UI自动化框架时看到过这种行为?感谢您的时间.

这是监视器代码(我知道事件处理在这里的UI自动化线程上,但是将它移动到专用线程并没有改变任何东西):

        public void registerHandlers()
    {
        //Register on structure changed and window opened events 
        System.Windows.Automation.Automation.AddStructureChangedEventHandler(
            this.getMsAutomationElement(), System.Windows.Automation.TreeScope.Subtree, this.handleStructureChanged);
        System.Windows.Automation.Automation.AddAutomationEventHandler(
            System.Windows.Automation.WindowPattern.WindowOpenedEvent,
            this.getMsAutomationElement(),
            System.Windows.Automation.TreeScope.Subtree,
            this.handleWindowOpened);
        System.Windows.Automation.Automation.AddAutomationEventHandler(
            System.Windows.Automation.WindowPattern.WindowClosedEvent,
            System.Windows.Automation.AutomationElement.RootElement,
            System.Windows.Automation.TreeScope.Subtree,
            this.handleWindowClosed);

        this.registerValueChanged();
        this.registerTextNameChange();
        this.registerTabSelected();
        this.registerRangeValueChanged();
    }

    private void registerRangeValueChanged()
    {
        if (this.getMsAutomationElement() != null)
        {
            System.Windows.Automation.Automation.AddAutomationPropertyChangedEventHandler(
                    this.getMsAutomationElement(),
                    System.Windows.Automation.TreeScope.Subtree, this.handlePropertyChange,
                    System.Windows.Automation.RangeValuePattern.ValueProperty);
        }
    }

    private void unregisterRangeValueChanged()
    {
        System.Windows.Automation.Automation.RemoveAutomationPropertyChangedEventHandler(
                this.getMsAutomationElement(),
                this.handlePropertyChange);
    }

    private void registerValueChanged()
    {
        if (this.getMsAutomationElement() != null)
        {
            System.Windows.Automation.Automation.AddAutomationPropertyChangedEventHandler(
                this.getMsAutomationElement(),
                System.Windows.Automation.TreeScope.Subtree, this.handlePropertyChange,
                System.Windows.Automation.ValuePattern.ValueProperty);
        }
    }

    private void …
Run Code Online (Sandbox Code Playgroud)

c# ui-automation microsoft-ui-automation wpf-4.0

11
推荐指数
2
解决办法
3164
查看次数