我在解压文件时遇到了一些问题。一切正常进展条输出和提取。但是当它运行时,UI会冻结。我尝试过使用Task.Run()
,但是它并不能很好地处理进度条。或者,也许我只是没有正确使用它。C#使用sevenzipsharp进行解压缩并更新无UI冻结的进度栏
有什么建议吗?
private void unzip(string path)
{
this.progressBar1.Minimum = 0;
this.progressBar1.Maximum = 100;
progressBar1.Value = 0;
this.progressBar1.Visible = true;
var sevenZipPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Environment.Is64BitProcess ? "x64" : "x86", "7z.dll");
SevenZipBase.SetLibraryPath(sevenZipPath);
var file = new SevenZipExtractor(path + @"\temp.zip");
file.Extracting += (sender, args) =>
{
this.progressBar1.Value = args.PercentDone;
};
file.ExtractionFinished += (sender, args) =>
{
// Do stuff when done
};
//Extract the stuff
file.ExtractArchive(path);
}
您正在运行的主线程上的一切让进度条工作要么你需要使用后台辅助类或展示如何使用进度对象创建自己的线程 – Krishna