title: Call Method From BackgroundWorker
body: <p>I hate that my first question seems to have been answered many times, but I'm still having a tough time getting my head around how to call a method using BackgroundWorker.</p>
  
  <p>I'm processing a very large text file using a series of classes and methods. The entire process is kicked off after the user selects a tool strip item. Sequentially, it goes like this:</p>
  
  <ul>
  <li>User selects the tool strip item</li>
  <li>User selects a file to be processed via a dialog box</li>
  <li>The action starts</li>
  </ul>
  
  <p>I think I can wrap everything into BackgroundWorker from the moment the user pops the initial dialog box, but what I'd like to do for now is just put the method where all the heavy lifting is done into its own instance of BackGroundWorker. I'll add a ProgressBar, too, but I think I can handle that if I can just get the BackgroundWorker process rolling.</p>
  
  <p>From the top (pseudocode used for example purposes. Much omitted for brevity):</p>
  
  <pre><code>private void ToolStripMenuItem_Click(object sender, EventArgs e)
  {
       string fileName = openSingleFile.FileName;
       processFile(fileName); 
  }
  
  static public void processFile(string fileName)
  {
  // many vars/loops exist but not shown
  
      foreach (data in bigData)
      {
          processItem(stringA, stringB); // &lt;-- this method is where the expensive work is done 
          x++; 
      }  
  } 
  </code></pre>
  
  <p>I've created an instance of BackgroundWorker...:</p>
  
  <pre><code>private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  {
      // Things go here
  }
  </code></pre>
  
  <p>...and I've tried too many things to list, so I've gone back to the beginning for the presentation above.</p>
  
  <p>If I'm understanding BackgroundWorker, I'll need to do the following:</p>
  
  <ul>
  <li><p>Replace processItem(stringA, stringB) in the above code with something like: </p>
  
  <p><code>backgroundWorker1.RunWorkerAsync(processItem(stringA, stringB));</code></p></li>
  </ul>
  
  <p>...and then do some type of DoWork call?
  ...and then do some type of RunWorkerCompleted call?</p>
  
  <p>Not sure why my brain is freezing, but I'm embarrassed at the amount of time I've spent on this with no result. Any help would be greatly appreciated. Without StackOverflow, I would have been DOA a long time ago.</p>
  
  <p>FYI: I've referenced other SO posts, MSDN, and DotNetPerls examples. I'm just missing something conceptually, I suppose.</p>