0

The intention is to make a progress bar move according to the compression of files, but it only works in the decompression (not showed on code), where is the problem?

private void Compress(string source)
{
    progressBar1.Minimum = 0;
    progressBar1.Maximum = 100;
    progressBar1.Value = 0;
    progressBar1.Visible = true;

    var progressHandled =
        new Progress<byte>(percentDone => progressBar1.Value = percentDone);
    var progress = progressHandled as IProgress<byte>;

    Task.Run(() =>
    {
        string SZpath = Directory.GetCurrentDirectory() + @"\64-7z.dll";

        SevenZipBase.SetLibraryPath(SZpath);

        SevenZipCompressor compressor = new SevenZipCompressor();
        compressor.ArchiveFormat = OutArchiveFormat.Zip;
        compressor.TempFolderPath = Path.GetTempPath();
        compressor.CompressionMode = SevenZip.CompressionMode.Create;
        compressor.CompressionLevel = SevenZip.CompressionLevel.Fast;
        compressor.CompressionMethod = CompressionMethod.Lzma;
        compressor.ZipEncryptionMethod = ZipEncryptionMethod.Aes256;

        compressor.Compressing += (sender, args) =>
        {
            progress.Report(args.PercentDone);
        };
        compressor.CompressionFinished += (sender, args) =>
        {

        };
        compressor.CompressDirectory(source, @"A:\C#\empty\archive.zip", "password");
    });
        log("Ended"); // the void is not on code
}

The code works perfectly, the problem is that the progressbar never moved

Thank you for your time, I look forward to your answer.

3301c
  • 1
  • 2
  • Someone wrote that compression level `Fast` doesn't fire events. E.g: https://stackoverflow.com/questions/46278864/sevenzipsharp-events-not-firing – Loathing May 16 '21 at 20:22
  • i tried `SevenZip.CompressionLevel.Ultra;` and `SevenZip.CompressionLevel.Normal;` and still being the same... – 3301c May 18 '21 at 01:28
  • i also tried `compressor.FastCompression = false;` – 3301c May 18 '21 at 01:30
  • If a breakpoint is set on the line `progress.Report(args.PercentDone);` does it get hit? – Loathing May 18 '21 at 02:01
  • https://stackoverflow.com/questions/23860160/sevenzip-compressing-event-not-firing – Loathing May 18 '21 at 02:15

0 Answers0