title: AutomationElement.FromHandle(IntPtr Handle) stops the application
body: <pre><code>private string GetCurrentChromeUrl()
      {
          try
          {
              string url = null;
  
              int handle = GetForegroundWindow();
              AutomationElement elm = AutomationElement.FromHandle((IntPtr)handle);
              AutomationElement elmUrlBar = elm.FindFirst(TreeScope.Descendants,
                    new PropertyCondition(AutomationElement.NameProperty, "Address and search bar"));
              if (elmUrlBar != null)
              {
                  AutomationPattern[] patterns = elmUrlBar.GetSupportedPatterns();
                  if (patterns.Length &gt; 0)
                  {
                      ValuePattern val = (ValuePattern)elmUrlBar.GetCurrentPattern(patterns[0]);
                      url = val.Current.Value;
                      //break;
                  }
              }
              return url;
          }
          catch (Exception e1)
          {
              return "";
          }
     }
  </code></pre>
  
  <p>I'm trying to find the URL from google chrome browser.</p>
  
  <p>And  I'm using above code. It is work good in other application but in my case it stops my application.</p>
  
  <p>But the main issue  is that it will work fine when I'm debugging it, so what wrong when no debugging.</p>
  
  <p>please give your solutions.</p>
  
  <p>thanx in advance</p>