title: How can I update a UI progressbar or backgroundworker from code in a separate class?
body: <p>Somewhat new to C# but I have a major problem with getting these things to work because if my background worker is running a long process by using a method from another class, then that class has no access to the background worker in order to update the progress.</p>
  
  <p>For instance:</p>
  
  <pre><code>private void bgWorker_DoWork(object sender DoWorkEventArgs e)
  {
      bgArgs args = e.Argument as bgArgs;
      MyClass objMyClass = new MyClass();
  
      MyClass.MyMethod(strValue, args.Option);
  
      //Do something based on return value of long process.
  }
  </code></pre>
  
  <p>If I try to update bgWorker from the class "MyClass", it cannot "see" bgWorker, it doesn't exist in the context of the class, it's in the UI class because in Visual Studio, that's where you drag it from the toolbox.</p>
  
  <p>The only way I've gotten it to work is to pass the whole UI form to the class, which creates other problems when trying to access that class from anywhere but the main form. From there I just update the progress bar manually via ProgressBar1.PerformStep() as it runs through the loops.</p>
  
  <p>Also, I've already changed the modifier on my progress bar to internal, so it's not that the class doesn't see the progress bar.</p>
  
  <p>I might be able to pass the bgworker by itself to the class through the method, but that just doesn't seem right.</p>