private void bw_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; using (SevenZipArchive archive = new SevenZipArchive(Globals.rarFile)) { int i = 0; int max = archive.Count(); int curPercent = 0; foreach (ArchiveEntry entry in archive) { try { entry.Extract(Globals.workDirectory + "data\\patch\\temp\\"); } catch (SevenZipException ex) { MessageBox.Show("Error:\n" + ex); } // Increment & update stats as well as progress bar i++; // This operating will only get to 50%, and the file transfer will be the other 50% curPercent = (((i * 100) / max) / 2); // Update the UI if ((worker.CancellationPending == true)) { e.Cancel = true; break; } else { // Perform a time consuming operation and report progress. System.Threading.Thread.Sleep(50); worker.ReportProgress(curPercent); } } int lastPercent = curPercent; //DirectoryInfo dir = new DirectoryInfo(Globals.workDirectory + "data\\patch\\temp\\"); String[] allfiles = System.IO.Directory.GetFiles(Globals.workDirectory + "data\\patch\\temp\\", "*.*", System.IO.SearchOption.AllDirectories); max = allfiles.Length; i = 0; foreach (string file in allfiles) { //MessageBox.Show("Moving: " + file + "\nTo: " + Globals.rarExtractToLocation + Path.GetFileName(file)); Directory.Move(file, Globals.rarExtractToLocation + Path.GetFileName(file)); i++; curPercent = (((i * 100) / max) / 2); curPercent += lastPercent; // Update the UI if ((worker.CancellationPending == true)) { e.Cancel = true; break; } else { // Perform a time consuming operation and report progress. System.Threading.Thread.Sleep(50); worker.ReportProgress(curPercent); } } } //MessageBox.Show("Unrar Complete"); //this.Close(); }