What setting needs to be made to make .Net Automation responsive?

Posted by Greg on Stack Overflow See other posts from Stack Overflow or by Greg
Published on 2010-05-20T23:19:53Z Indexed on 2010/05/20 23:20 UTC
Read the original article Hit count: 256

Have an app that is looking for application windows being created on the desktop using

class Unresponsive {
  private StructureChangedEventHandler m_UIAeventHandler = new StructureChangedEventHandler(OnStructureChanged);

  public Unresponsive() {
    Automation.AddStructureChangedEventHandler(AutomationElement.RootElement, TreeScope.Children, m_UIAeventHandler);
  }

  private void OnStructureChanged(object sender, StructureChangedEventArgs e) {
    Debug.WriteLine("Change event");
  }
}

You can see the same issue using UISpy.exe, selecting the desktop and configuring scope for children and just the structure changed event.

The problem I'm trying to resolve is that the events are not raised in a timely manner, there seems to be some grouping/delay which makes the app appear to be non responsive.

If you start a new app with 1 window and wait a second you get the event, seems alright.

If you start the same app several times without delay (say clicking on quickstart), it's not until all of the instances of the app get 'initialised' by the AutomationProxies that you get the notice for the first app (and in short order the other apps/windows). I've sat watching task manager as each instance of the app starts to grow as it is initialised, waiting until the last app is done and then seeing the events all come in.

Similarly any time any apps are starting windows within a timeframe there seems to be some blocking. I can't see how to configure this timeframe, or get each structure changed event to be sent on as soon as it happens.

Also, this process of listening for structure changed events seems to be leaking, just by listening there is a leak in native memory. (visible in UISpy and my app)

© Stack Overflow or respective owner

Related posts about automation

Related posts about .NET