拋出我有以下代碼:異常由調用的目標BackgroundWorker的
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()
)?
任何幫助,將不勝感激。
它在'Application.Run(new MainWindow());'在Program.cs – davidwroxy 2013-03-25 01:39:03
中斷了哦,對不起,它實際上不在那裏。它在'progbarExtract.Value = Convert.ToInt32(e.ProgressPercentage);' – davidwroxy 2013-03-25 01:44:33
這是我猜測的。請注意,ProgressPercentage大於100.我解釋了爲什麼,您的步驟值是錯誤的。 – 2013-03-25 02:15:33