title: TestStack.White Menu Operations Affected by System Busy State
body: <p>This is Windows 10 UI automation testing via <code>nunit3.ConsoleRunner</code>.</p>
  
  <p>It is really pretty weird, but the same code that worked flawlessly before my vacation now hangs for so far up to 2 hours or more. I created my own <code>MenuClick()</code> method for our tests because the standard <code>MenuBar.MenuItem()</code> method frequently hung as well when navigating past 2nd level menu items. My method worked fine before my vacation, as I said.</p>
  
  <p>Anyway, now, the <code>Menu.SubMenu()</code> call frequently takes 2 hours or more to complete, which is unacceptable.</p>
  
  <p>An additional bit of weirdness is that the test code clicks 3rd level menuitems in pairs, where they both open a Browse For Folder dialog. The first to select a source folder and the other to select a destination folder. The "hang" ONLY occurs (so far) when attempting to get the 2nd level <code>submenu</code> for the second in the pair of 3rd level menuitem clicks.</p>
  
  <p>To get around this currently, I'm spawning a new thread that invokes menu = menuBar.MenuItem(). In the  main thread, I wait for menu to be non-null or for timeout to occur before proceeding with a 500 ms sleep between checks. That at least allows me to retry. However, it is appearing that, when this condition occurs, the rest of the menu operations in the entire application under test are hung, so I'm unable to retry. Seems like a bug in the TestStack.White menu handling area.</p>
  
  <pre><code>    public static void GetSubMenu(object obj)
  {
      string[] menuNames = obj as string[];
      menu = menuBar.MenuItem(menuNames);
  }
  
  private static MenuBar menuBar = null;
  private static Menu menu = null;
  
  public static int ClickMenu(MenuBar mainMenu, params string[] menuItems)
  {
      menuBar = mainMenu;
      bool bDone = false;
      menu = null;
  
      System.Threading.Thread t = new System.Threading.Thread(GetSubMenu);
      t.Start(menuItems);
      System.Threading.Thread.Sleep(500);
  
      DateTime timeOut = DateTime.Now + TimeSpan.FromSeconds(10);
  
      while (menu == null &amp;&amp; DateTime.Now &lt; timeOut)
      {
          System.Threading.Thread.Sleep(500);
      }
  
      if (menu != null)
      {
          menu.Click();
          bDone = true;
          log.Info($"ClickMenu success");
      }
  
      t.Abort();
  
      return bDone ? 1 : 2;
  }
  </code></pre>