Progressbar with Backgroundworker and DoEvent

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von EaranMaleasi.

    Progressbar with Backgroundworker and DoEvent

    Hi, I'm newbie here.
    Can anybody help me to use
    progressbar with backgroundworker properly?
    I did research but I always failed maybe I can find the answer in your comment.
    You can
    comment

    in German I used
    the code from this post:Backgroundworker and Progressbar


    My
    problem is the result is

    Not 100% but it's not accurate result

    Here's the code
    that I've been using

    Quellcode

    1. Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    2. Dim folder As String = txtSource.Text
    3. Dim encryptionKey As Byte() = File.ReadAllBytes(txtKey.Text)
    4. Dim outputFile As String = (txtFilePath.Text + "" + txtFileName.Text + ".ts")
    5. Using outputFileStream As File FileStream = New FileStream(outputFile, FileMode.Create)
    6. Dim files = Directory.GetFiles(folder, "*.ts")
    7. For i As Integer = 0 To files. Length - 1
    8. Dim encryptionIV As Byte() = New Byte(15) {}
    9. Using inputFileStream As FileStream = New FileStream(files(i), FileMode.Open)
    10. Using aes = New AesManaged With {
    11. .Key = encryptionKey,
    12. .IV = encryptionIV,
    13. .Mode = CipherMode.CBC
    14. }-
    15. Using encryptor = aes. CreateDecryptor()
    16. Using cryptoStream = New CryptoStream(inputFileStream, encryptor,CryptoStreamMode.Read)
    17. '''BACKGROUNDWORKER START
    18. Application.DoEvents()
    19. Dim p As Long
    20. For x As Integer = 0 To 100
    21. p += 1
    22. Next
    23. BackgroundWorker1.ReportProgress(100, p)
    24. ''''BACKGROUNDWORKER END
    25. cryptoStream.CopyTo(outputFileStream)
    26. End Using
    27. End Using
    28. End Using
    29. End Using Next
    30. End Using End Sub



    [code]Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged

    Label6.Text = e.UserState.ToString

    End Sub

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „zackmark29“ ()

    Hey @zackmark29 welcome to this forum,

    While the Backgroundworker and Application.DoEvents are heavily outdated and should be replaced by more modern approaches, it'd be best for you to show us a bit of your code and tell us what your're trying to achieve, which approaches you've tested, and what exactly failed.

    Note that the editor has options to enable syntax highlighting for pieces of code making it easier to read.