title: C# update and append textbox value using backgroundworker process
body: <p>I've got a c# windows form app I threw together.  It's fairly simple:\</p>
  
  <p>inputs:</p>
  
  <ul>
  <li>text string </li>
  <li>source folder path</li>
  <li>destination folder path </li>
  <li>integer count</li>
  </ul>
  
  <p>The app searches through text files in the source folder for the entered text string; if it finds the string then it copies that file and an image file with the same name to the destination folder.  It does this however many times based on the integer input.</p>
  
  <p>So I have a button, and in the button click event I call</p>
  
  <pre><code>ProcessImages(tbDID.Text, tbSource.Text, tbDest.Text, comboBoxNumberImages.SelectedItem.ToString());
  </code></pre>
  
  <p>which is:</p>
  
  <pre><code>private void ProcessImages(string DID, string SourceFolder, string DestFolder, string strNumImages)
          {         
              int ImageCounter = 0;
              int MaxImages = Convert.ToInt32(strNumImages);
  
              DirectoryInfo di = new DirectoryInfo(SourceFolder);
  
              foreach (FileInfo fi in di.GetFiles("*.txt"))
              {
                  if (fi.OpenText().ReadToEnd().Contains(DID))
                  {
                      //found one!
                      FileInfo fi2 = new FileInfo(fi.FullName.Replace(".txt", ".tif"));
                      if (fi2.Exists)
                      {
                          try
                          {
                              tbOutput.Text += "Copying " + fi2.FullName + " to " + tbDest.Text + "\r\n";
                              fi2.CopyTo(tbDest.Text + @"\" + fi2.Name, true);
                              tbOutput.Text += "Copying " + fi.FullName + " to " + tbDest.Text + "\r\n";
                              fi.CopyTo(tbDest.Text + @"\" + fi.Name, true);
  
                              ImageCounter++;
                          }
                          catch (Exception ex)
                          {
                              MessageBox.Show(ex.Message);
                          }
                      }
                  }
  
                  if (ImageCounter &gt;= MaxImages)
                      break;
  
              }
  
          }
  </code></pre>
  
  <p>What happens is that the process runs fine, but I want to update a textbox on the form with progress as the files are copied.  Basically the form blanks out while it's running, and after it's finished the output is in the textbox.  I'd like to implement a BackgroundWorker get it to update the UI while it's running.</p>
  
  <p>I've looked through the examples but am not really following them.  I don't have a percentage complete value, I just want to update .Text changes each iteration and have it display.  I don't even think I necessarily need to put the actual copying action in different threads, it just sounds like that needs to be run separately from the main UI thread.  Maybe I'm over complicating this altogether...can someone push me in the right direction?  Thanks!</p>