title: Thread safety / Invoke method causes StackOverflowException
body: <p>This is an app that uses WMI to fetch Local Administrator group members on a remote computer. In an attempt to make threadsafe calls to update my main UI from within Background Worker I am getting a StackOverflowException. I have copied the example from another thread on Stack. Could someone help me to identify the cause?</p>
  
  <pre><code>private void getLocalAdministrators(string serverName)
      {
          try
          {
              System.Management.ManagementScope scope = new System.Management.ManagementScope("\\\\" + serverName + "\\root\\cimv2");
              scope.Connect();
  
              StringBuilder qs = new StringBuilder();
              qs.Append("SELECT PartComponent FROM Win32_GroupUser WHERE GroupComponent = \"Win32_Group.Domain='" + serverName + "',Name='" + "Administrators'\"");
  
              System.Management.ObjectQuery query = new System.Management.ObjectQuery(qs.ToString());
              System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(scope, query);
  
              foreach (System.Management.ManagementObject group in searcher.Get())
              {
                  string groupDetails = serverName + tab + group["PartComponent"].ToString() + tab;
  
                  string domainPart = groupDetails.Split('=')[1];
                  domainPart = domainPart.Replace("\"","").Replace(",Name","");
  
                  string accountPart = groupDetails.Split('=')[2];
                  accountPart = accountPart.Replace("\"", "");
  
                  if (query != null)
                  {
                      updateUISafely(serverName + tab + domainPart + tab + accountPart);
                  }
                  else
                  {
                      updateUISafely("Error with: " + serverName);
                  }
              }
          }
          catch (Exception ex)
          {
              updateUISafely("Error with: " + serverName + ". " + ex.Message);
          }
  
      }
  
      public delegate void ProcessResultDelegate(string result);
      void updateUISafely(string result)
      {
          if (textBox2.InvokeRequired)
          {
              var d = new ProcessResultDelegate(updateUISafely);
              d.Invoke(result);
          }
          else
          {
              textBox2.AppendText(result + nl);
          }
      }
  
  
      private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
      {
          string[] strArray;
          strArray = textBox1.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
  
          int objectCount = strArray.Count();
          int count = 0;
  
          foreach (string str in strArray)
          {
              getLocalAdministrators(str);
              count++;
              backgroundWorker1.ReportProgress((100 * count) / objectCount);
          }
      }
  
      private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
      {
          progressBar1.Value = e.ProgressPercentage;
      }
  
      private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          foreach (string item in resultsList)
          {
              textBox2.AppendText(item + Environment.NewLine);
          }
          btnGet.Enabled = true;
      }
  </code></pre>