title: For Loop Inside BackgroundWorker.DoWork
body: <p>Basically, What I have is One background worker. A button gets clicked and that button has BackgroundWorker.DoWork The DoWork fucntion has this code:</p>
  
  <pre><code>For Each item In lst_Folders.CheckedItems
          Dim path As String = My.Settings.stng_sourceDirectory + "\" + item.Text
          For Each dirPath As String In Directory.GetDirectories(path, "*", SearchOption.AllDirectories)
              Directory.CreateDirectory(dirPath.Replace(path, My.Settings.stng_saveDirectory + "\" + item.Text))
          Next
  
          'Copy all the files &amp; Replaces any files with the same name
          For Each newPath As String In Directory.GetFiles(path, "*.*", SearchOption.AllDirectories)
              File.Copy(newPath, newPath.Replace(path, My.Settings.stng_saveDirectory + "\" + item.Text), True)
          Next
   Next
  </code></pre>
  
  <p>It's basically copying and pasting directories depending on which ListViewItem is checked. The problem is that Once I click on the button, the Background does work but immediately I get an error saying</p>
  
  <p><code>Cross-thread operation not valid: Control 'lst_Folders' accessed from a thread other than the thread it was created on.</code></p>
  
  <p>Can someone please assist me with this problem. I'm just not sure why it wont work.</p>