0

I want to add process bar when SevenZipSharp is compressing files/folders.

I wrote something like: (check out comments)

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
...
...
...

and Void for 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); }));
    }

But, as you probably guessed, doesn't work.

Edit:

ok so now i added:

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 started BUT program frezzing about 97%-98% and nothing happens. I think i must create new Thread. Can someone help me with it please?

Kafus
  • 61
  • 1
  • 14
  • What exactly doesn't work? Does your program ever enter compressing event? – msmolcic Jul 19 '15 at 09:48
  • well i think it started but nothing else... only start without error but doesn't compress- freezed – Kafus Jul 19 '15 at 10:37
  • i edited post. Can u check it pls? – Kafus Jul 19 '15 at 11:16
  • You are fire-hosing the UI thread, invoking much more often than necessary. The Sleep() call is a band-aid, slowing down the invoke rate. And never use Invoke() if you can avoid it, very apt to cause deadlock. Always use BeginInvoke() instead. – Hans Passant Jul 19 '15 at 11:29
  • Well ok. I deleted all from compressor_Compressing and it's ok (of course except progressBar) but when ill add something to this void, application freeze. I changed invoke for BeginInvoke but nothing changed. I delete Sleep()- progressBar is running but again app freeze. – Kafus Jul 19 '15 at 12:13
  • Anybody know, how can i repair this ? – Kafus Jul 21 '15 at 09:10

0 Answers0