Answered Progressbar only 51%

zackmark29

Active member
Joined
Apr 21, 2020
Messages
28
Programming Experience
Beginner
Could someone help me fix this codes?
It's only getting 51% result when the process is done


VB.NET:
 Dim counter As Double = 1
        Dim outputFolder As String = txtFileOutput.Text + "\" + txtFileName.Text + ".ts"
        Dim encryptionKey As Byte() = File.ReadAllBytes(txtKeyFile.Text)
        Dim inputFilestream As FileStream
        Dim outputFilestream As FileStream
        Try
            outputFilestream = New FileStream(outputFolder, FileMode.Create, FileAccess.Write, FileShare.ReadWrite, FileOptions.SequentialScan)

            For Each obj2 As Object In ListView1.Items
                Dim sourceitem2 As SourceItem = CType(obj2, SourceItem)

                Dim encryptionIV As Byte() = New Byte(15) {}

                inputFilestream = New FileStream(sourceitem2.FileName, FileMode.Open, FileAccess.Read, FileShare.Read, FileOptions.SequentialScan)

                Dim aes As New AesManaged With {
                    .Key = encryptionKey,
                    .IV = encryptionIV,
                    .Mode = CipherMode.CBC
                }

                Dim encryptor = aes.CreateDecryptor()
                Dim cryptoStream = New CryptoStream(inputFilestream, encryptor, CryptoStreamMode.Read)

                Dim count = sourceitem2.FileName.Length

                'PROGRESSBAR
                Dim value As Double = (counter / sourceitem2.FileName.Length) * 100
                BackgroundWorker1.ReportProgress(CInt(value))

                cryptoStream.CopyTo(outputFilestream)

                counter += 1

                inputFilestream.Close()
            Next
            outputFilestream.Flush()
            outputFilestream.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
 
Dim value As Double = (counter / sourceitem2.FileName.Length) * 100
Shouldn't progress be measured against the count of ListView1.Items that is looped?
 
Shouldn't progress be measured against the count of ListView1.Items that is looped?

I've already fixed this Admin.
What I did is just count the items inside the listview and it worked.
But do you suggest some way to make the process faster? it looks like the progressbar is causing the process become slow
 
What I did is just count the items inside the listview and it worked.
ListViewItemCollection has a Count property, no need to count them yourself :)
it looks like the progressbar is causing the process become slow
Updating progress in UI should have a neglectable CPU impact to a file based cryptographic process.
 
ListViewItemCollection has a Count property, no need to count them yourself :)
ahm. could you give me sample to make changes for my progressbar?
I'm processing files inside the listview

Updating progress in UI should have a neglectable CPU impact to a file based cryptographic process.
So it's just normal? sometimes the process is faster
Is there any method to make the process less cpu and ram usage?
 
ListView1.Items.Count is the count of the items in the listview, if that is the count you're looking for.
 

Latest posts

Back
Top