updating richtextbox, thread problem

Nov 1, 2012 at 10:58 AM
Edited Nov 1, 2012 at 10:58 AM

Hello friends,

Very nice work with wrapper! I need some assistance please :)

In many projects I have a class named 'console' which basically creates a second form with a richtextbox on it so all project forms can output messages. The method to display messages is following

 

        Private Delegate Sub addLineDelegate(ByVal str As String)

        Public Sub addLine(ByVal str As String)
            If rtb.InvokeRequired Then
                Dim d As New addLineDelegate(AddressOf Me.addLine)
                rtb.BeginInvoke(d, New Object() {str})
            Else
                Try
                    rtb.SelectionColor = Color.Black
                    rtb.AppendText("> " + str + vbCrLf)
                    rtb.SelectionStart = rtb.Text.Length
                    rtb.ScrollToCaret()
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End If
        End Sub

 

And this is what I try to acheive

 

   Public Sub fCompressionFinished(ByVal sender As Object, ByVal e As System.EventArgs)

        console.addLine("Compression finished.")

    End Sub

    Private Sub fFileCompressionStarted(ByVal sender As Object, ByVal e As SevenZip.FileNameEventArgs)

        console.addLine("Compressing " + e.FileName)

    End Sub

 

Which basically works nice but 'finished event' is fired before actually finishing file compressions :) this is my buggy implementation or what's happening ? This is actual output:

 

> Compressing flat_src1.zip
> Compressing UpgradeReport_Minus.gif
> Compressing UpgradeReport_Plus.gif
> Compressing AssemblyInfo.vb
> Compressing FlatCombo.vb
> Compressing Form1.vb
> Compressing FlatCombobox2.vshost.exe.manifest
> Compressing FlatCombobox2.sln
> Compressing FlatCombobox2.xml
> Compressing FlatCombobox2.xml
> Compressing UpgradeLog.XML
> Compressing UpgradeReport.xslt
> Compressing UpgradeReport.css
> Compressing FlatCombobox2.vbproj.FileListAbsolute.txt
> Compressing FlatCombobox2.pdb
> Compressing FlatCombobox2.pdb
> Compressing DesignTimeResolveAssemblyReferences.cache
> Compressing DesignTimeResolveAssemblyReferencesInput.cache
> Compressing app.config
> Compressing FlatCombobox2.exe.config
> Compressing FlatCombobox2.vshost.exe.config
> Compressing FlatCombobox2.FlatCombo.resources
> Compressing FlatCombobox2.Form1.resources
> Compressing FlatCombo.resx
> Compressing Form1.resx
> Compressing FlatCombobox2.suo
> Compressing GenerateResource.read.1.tlog
> Compressing GenerateResource.write.1.tlog
> Compressing FlatCombobox2.vbproj.user
> Compressing FlatCombobox2.vbproj
> Compression finished.
> Compressing FlatCombobox2.exe
> Compressing FlatCombobox2.exe
> Compressing FlatCombobox2.vshost.exe

 

Any idea?

Thanks very much in advance

Edouard Gora 

 

Nov 1, 2012 at 5:32 PM

Hmm... seems to be solved for moment using BeginCompressDirectory() instead of CompressDirectory(). I noticed for little compressible files, compression started event is started in other thread than UI but since I'm not a expert in multi-threading I don't know exact cause or how to overcome. 

By using BeginCompressDirectory() all event triggers are in the same thread now :)