This project is read-only.

VB.NET 2010, compression and progress bar

Dec 14, 2012 at 3:14 PM


I'm trying to compress a file with sevenzipsharp and display the status with a progresbar in my VB.NET 2010 project.

The following example stays hanging. No error message, no popup, it's not even frozen, just nothing seems to happen.

If a set a breakpoint at "Private Sub cmp_Compressing", I see that the first loop is ok, then the second loops starts and nothing happens.

Any idea ? Thanks


Imports SevenZip

Public Class Form1

    Private Delegate Sub SetProgressDelegate(ByVal amt As Byte)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'tried both version 32-64
        'SevenZipCompressor.SetLibraryPath("C:\Program Files\7-Zip\7z.dll")
        SevenZipCompressor.SetLibraryPath("C:\Program Files (x86)\7-Zip\7z.dll")
        Dim tmp As SevenZipCompressor = New SevenZipCompressor()

        AddHandler tmp.Compressing, AddressOf cmp_Compressing

        tmp.CompressionMethod = CompressionMethod.Lzma
        tmp.ScanOnlyWritable = True
        tmp.CompressFiles("C:\test\1\test.7zip", "C:\test\somefileto7zip.bla")

    End Sub

    Private Sub cmp_Compressing(ByVal sender As Object, ByVal e As ProgressEventArgs)
    End Sub

    Private Sub SetProgress(ByVal amt As Byte)
        If Me.InvokeRequired Then
            ' If this function was called on a background thread, 
            ' jump over to the main thread.
            Dim thisSub As SetProgressDelegate = AddressOf SetProgress
            'also tried that
            'Dim thisSub As New SetProgressDelegate(AddressOf SetProgress)
            Me.Invoke(thisSub, amt)
            ' If this function is running on the UI thread
            ' update the property.
            ProgressBar1.Value = amt
        End If
    End Sub

End Class