I have the following 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) =>
{
progbarExtract.Value = Convert.ToInt32(e.ProgressPercentage);
};
lblExtracting.Text = "Extracting...";
worker.DoWork += (o, e) =>
{
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();
}
I don't understand why the statement percentComplete += step;
causes an error (Exception has been thrown by the target of an invocation.
).
How could I fix this?
Also, does anybody knows how could I display a message box (MessageBox.Show()
) when extraction is complete?
Any help would be appreciated.