我有以下代码:
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();
}
我不明白为什么该语句percentComplete += step;
会导致错误(Exception has been thrown by the target of an invocation.
)。
我该如何解决这个问题?
另外,有人知道MessageBox.Show()
提取完成后如何显示消息框( )吗?
任何帮助,将不胜感激。