添加ProcessBar进行压缩 - SevenZipSharp

时间:2015-07-19 09:30:30

标签: c# compression progress-bar sevenzipsharp

我想在process bar压缩文件/文件夹时添加SevenZipSharp

我写了类似的东西:(签出评论

private void buttonCompress_Click(object sender, EventArgs e)
    {

        SevenZip.SevenZipCompressor.SetLibraryPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"SevenZipSharp.dll"));
        if (IntPtr.Size == 8) //x64
            SevenZip.SevenZipExtractor.SetLibraryPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"7z64.dll"));
        else //x86
        SevenZip.SevenZipExtractor.SetLibraryPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"7z.dll"));


compressor.Compressing += new EventHandler<ProgressEventArgs>(compressor_Compressing); // <-- Handler for progressBar
...
...
...

Void progressBar

void compressor_Compressing(object sender, ProgressEventArgs e)
    {   
      this.Invoke(new MethodInvoker(delegate { progressBar1.Value = e.PercentDone;}));  
      //i tired this too: this.Invoke(new MethodInvoker(delegate {compressor_Compressing(sender, e); }));
    }

但是,正如你可能猜到的那样,不起作用。

修改

好的,所以现在我补充道:

void compressor_Compressing(object sender, ProgressEventArgs e)
    {
        if(InvokeRequired)   // <-- not necessary in this case
        {
            Thread.Sleep(10);   //<-- this is the key to run progressBar
            this.Invoke((new MethodInvoker(delegate { progressBar1.Value = e.PercentDone; })));
     }

ProcessBar启动 BUT 程序,大约97%-98%,没有任何反应。 我想我必须创建新的Thread。有人可以帮帮我吗?

0 个答案:

没有答案