title: c# delegate progressbar multithread and class in class
body: <p>I got my Winform(Class A) which uses Class B and
  Class B uses Class C</p>
  
  <p>Class C does stuff for me which reads word documents and retrieves data and pastes it in an excel file.
  I made a seperate Thread for that, so i can still move the winform around.</p>
  
  <p>Now i want my progressbar to view the value of which file it is working on from 0 to amountoffiles.</p>
  
  <p>It only updates while the form is the Active window.</p>
  
  <p>I got this currently in class C. Which i give the progressBar as parameter from Class A to B to C.</p>
  
  <pre><code>private void SetValue(int value)
  {
      // InvokeRequired required compares the thread ID of the
      // calling thread to the thread ID of the creating thread.
      // If these threads are different, it returns true.
      try
      {
          if (this.pbar.InvokeRequired)
          {
              if (Doc_converter.Form1.ActiveForm != null)
              {
                  SetTextCallback d = new SetTextCallback(SetValue);
                  Doc_converter.Form1.ActiveForm.Invoke(d, new object[] { value });
              }
          }
          else
          {
              this.pbar.Value = value;
          }
      }
      catch
      {
          //To do
      }
  }
  
  delegate void SetTextCallback(int value);
  </code></pre>
  
  <p>Is there a different way to get this done?</p>
  
  <p>Or a delegate from Class C to Class A?</p>
  
  <p>Keep in mind that it's a different thread than the form thread.</p>
  
  <p>Edit: Forgot to mention that i can only use .NET 4.0 or lower because the application has to run on a windows xp machine.</p>