解压缩大文件使我的程序关闭

Unzip large files make my program shutting down

我有一些代码可以解压我的 zip 文件。我有一个压缩文件:

每次我用我的程序解压缩它时,我的程序都会挂起,甚至不给我任何消息。

我的代码:

public void CreateZipContentFolder(List<String> zips, string destinationPath) {
        if (zips.Any()) {
            MyLog.WriteToLog("Unzipping Zip files to: " + destinationPath, MyLog.Messages.Info);
            foreach (string zip in zips) {
                string dirName = Path.Combine(destinationPath, Path.GetFileNameWithoutExtension(zip));

                //using (ZipArchive archive = ZipFile.OpenRead(zip)) {
                  //  foreach (ZipArchiveEntry entry in archive.Entries) {
                    //    if (entry.FullName.EndsWith("/")) {
                      //      ZipFile.ExtractToDirectory(zip, destinationPath);
                        //    break;
                        //} else if (!Directory.Exists(dirName)) {
                            Directory.CreateDirectory(dirName);
                            ZipFile.ExtractToDirectory(zip, dirName);
                  //          break;
                        //}
                    //}
                //}
            }
        } else { MyLog.WriteToLog("No Zip folders found.", MyLog.Messages.Warning); }
    }

我猜你的程序挂起是因为你调用的方法是一个阻塞方法。 这意味着该方法正在工作(提取),cpu 使用率应该很高。

让您的应用程序仍然响应的一个选项是在线程内调用 ZIP 方法。所以你的 UI 仍然可以响应,而且看起来你的应用程序不会崩溃。