WPF UI Automation issue

前端 未结 2 2130
傲寒
傲寒 2020-12-17 05:11

This Thread belong to this

I am asking where do I need to insert the workaround from this

I have a WPF application which has performance issue on some client

相关标签:
2条回答
  • 2020-12-17 05:31

    I have been working on an application that has been fine on virtually everything but the WPF Controls were slow on certain laptops (Lenovo). It was lagging and freezing and generally inhibiting use.

    I did the following:

    1. Implemented the code above: Improved it, but did not fix.
    2. Downloaded Hotfix - - http://archive.msdn.microsoft.com/KB978520 (may not be required)
    3. Downloaded Hotfix - - http://archive.msdn.microsoft.com/KB2484841 (definitely required even if you have Windows 7 / .NET 4)
    4. Improved the code further (the validation was causing an excess of objects) - Why does WPF Style to show validation errors in ToolTip work for a TextBox but fails for a ComboBox?

    It may be that only Number 3 was required, but it worked. Just posting here so people dont lose the days I lost in memory profilers etc.

    0 讨论(0)
  • 2020-12-17 05:38

    In my case it worked by adding that code to the main window. However, I simplified it a bit:

    public partial class MyMainWindow : Window
    {
        public MyMainWindow() {
              GotFocus += WindowGotFocus;
        }
    
        private void WindowGotFocus(object sender, RoutedEventArgs e)
        {
            WindowInteropHelper helper = new WindowInteropHelper(this);
            var mainWindowAutomationElement = AutomationElement.FromHandle(helper.Handle);
            Automation.AddStructureChangedEventHandler(mainWindowAutomationElement, TreeScope.Element,
                                                       delegate {});
            GotFocus -= WindowGotFocus;
        }
    }
    

    The only problem with this approach, in my machine, is that the debugger window gets cluttered with messages like:

    • A first chance exception of type System.Windows.Automation.ElementNotAvailableException' occurred in PresentationCore.dll
    • A first chance exception of type 'System.ArgumentException' occurred in UIAutomationClientsideProviders.dll
    • A first chance exception of type 'System.NotSupportedException' occurred in mscorlib.dll
    • A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in UIAutomationClient.dll

    All happening many many times. I couldn't fix these messages, but my application is running faster now.

    0 讨论(0)
提交回复
热议问题