title: How to (properly) cache AutomationElements for future use?
body: <p>In my test application, I am constantly opening and re-opening a form. Everytime the form is opened, I must get all the elements on the form into an <code>AutomationElementCollection</code> so that I can operate on the elements. However, it seems expensive to repeatedly get these elements (due to tree navigation/context-switches etc.).</p>
  
  <p>I attempted to set a boolean around the method that gets the elements. If the method was called for the first time, it would run normally, and set the boolean to true. If the method gets called a second time it will do nothing, as the array has already been populated. </p>
  
  <p>However when I try to perform operations on any <code>AutomationElement</code> in the array (for a second time), the elements do not seem to be available. Does closing the form somehow "disable" these elements? Do I HAVE to find these elements each time I open the form, so that they are "fresh"? </p>
  
  <p>I looked at the <code>CacheRequest</code> way, but that seems to only pertain to accessing properties/patterns, not elements.</p>
  
  <p>Here is code/error message: </p>
  
  <pre><code>AutomationElement GAP;
  AutomationElementcollection GAP1;
  private bool initGAP1 = false;
      public void initGAP()
      {
          if (!initGAP1)
          {
              int refnum = ...;
              int refnum2 = ...;
              AutomationElementCollection temp = MMChildren[refnum].FindAll(TreeScope.Children, findCondition);
              GAP = temp.FindAll(TreeScope.Children, findCondition)[refnum2];
              GAP1 = GAP.FindAll(TreeScope.Children, findCondition); //this contains the elements I want to operate on
              initGAP1 = true;
          }
      }
  </code></pre>
  
  <p>System.Windows.Automation.ElementNotEnabledException: Exception of type 'System.Windows.Automation.ElementNotEnabledException' was thrown.</p>