title: updating gui from another class c#
body: <p>hey i am new to c# plz help.
  i am writing a program that sorts data in a file and it is a time consuming process so i thought that i should run it in a separate thread and since it has alot of step so i made a new class for it. the problem is that i want to show the progress in the main GUI and i know for that i have to use Invoke function but the problem is that the form control variables are not accessible it this class. what should i do ??????</p>
  
  <p>sample code:</p>
  
  <pre><code>public class Sorter
  {
      private string _path;
      public Sorter(string path)
      {
          _path = path;
      }
  
      public void StartSort()
      {
          try
          {
                   processFiles(_path, "h4x0r"); // Just kidding
          }
          catch (Exception e)
          {
              MessageBox.Show("Error: " + e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
      }
  
      private void processFiles(string Dir, string[] key)
      {
          /* sorting program */
  
      }
  </code></pre>
  
  <p>and it is used as</p>
  
  <pre><code>    public partial class Form1 : Form
      {
          Sorter sort;
          public Form1()
          {
              InitializeComponent();
          }
  
          private void browseBtn_Click(object sender, EventArgs e)
          {
              if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                  textBox1.Text = folderBrowserDialog1.SelectedPath;
          }
  
          private void startBtn_Click(object sender, EventArgs e)
          {
              if (startBtn.Text == "Start Sorting")
              {
     Thread worker = new Thread(new ThreadStart(delegate() {
                  sort = new Sorter(textBox1.Text);
                  sort.StartSort(); })); 
                  worker.start();
              }
              else
                  MessageBox.Show("Cancel");//TODO: add cancelling code here
          }
      }
  </code></pre>
  
  <p>plz help..</p>