title: Exception thrown by target of invocation in BackgroundWorker
body: <p>I have the following code:</p>
  
  <pre><code>public void extractZipFile()
  {
      if (!System.IO.Directory.Exists(extractDirectory))
          System.IO.Directory.CreateDirectory(extractDirectory);
  
      BackgroundWorker worker = new BackgroundWorker();
      worker.WorkerReportsProgress = true;
      worker.ProgressChanged += (o, e) =&gt;
      {
          progbarExtract.Value = Convert.ToInt32(e.ProgressPercentage);
      };
  
      lblExtracting.Text = "Extracting...";
      worker.DoWork += (o, e) =&gt;
      {
          using (ZipFile zip = ZipFile.Read(zipFile))
          {
              int step = Convert.ToInt32(zip.Count / 100.0); 
              int percentComplete = 0; 
              foreach (ZipEntry file in zip)
              {
                  file.Extract(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XBMC Library Importer\\XBMC_Files", ExtractExistingFileAction.OverwriteSilently);
                      percentComplete += step; //When I comment this out I don't get an exception
                      worker.ReportProgress(percentComplete);
              }
          }
      };
  
      worker.RunWorkerAsync();
  }
  </code></pre>
  
  <p>I don't understand why the statement <code>percentComplete += step;</code> causes an error (<code>Exception has been thrown by the target of an invocation.</code>).</p>
  
  <p>How could I fix this?</p>
  
  <p>Also, does anybody knows how could I display a message box (<code>MessageBox.Show()</code>) when extraction is complete?</p>
  
  <p>Any help would be appreciated.</p>