Results 1 to 4 of 4

Thread: [RESOLVED] [2008] backgroundworker not reporting progress

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Resolved [RESOLVED] [2008] backgroundworker not reporting progress

    What am i missing here? I cant get the backgroundworker to report progress =/ I tried changing the progress change event handler and also my code and i cant pinpoint what im doing wrong, i havent used this in a long while so help plz

    vb.net Code:
    1. Private Sub Copying_backgroundworker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Copying_backgroundworker.DoWork
    2.         With My.Computer.FileSystem
    3.             Me.lblProgress.Invoke(New lblProgress_Delegate_Invoker(AddressOf lblProgress_Invoker), "Copying files...")
    4.             Dim sFiles As String() = IO.Directory.GetFiles(WorkingPatchDir)
    5.             Dim sFolders As String() = IO.Directory.GetDirectories(WorkingPatchDir)
    6.             Dim Amountoffoundfiles As Integer = IO.Directory.GetFiles(WorkingPatchDir).Count
    7.             Dim Amountoffoundfolders As Integer = IO.Directory.GetDirectories(WorkingPatchDir).Count
    8.             Dim Filecounter As Integer
    9.             Dim Foldercounter As Integer
    10.             Dim a As Integer = 0
    11.             Dim b As Integer = 0
    12.             Dim c As Integer = 0
    13.             Dim d As Integer = 0
    14.             Dim f As Integer = c + d
    15.             For Each Fullpath As String In sFiles
    16.                 File.Copy(Fullpath, Path.Combine(GameFolder, Path.GetFileName(Fullpath)), overwrite:=True)
    17.                 a += 1
    18.                 Filecounter += 1
    19.                 Me.lblUnpacked.Invoke(New lblUnpacked_Delegate_Invoker(AddressOf lblUnpacked_Invoker), "Copying file " & IO.Path.GetFileName(Fullpath))
    20.                 c = (100 * a / sFiles.Length)
    21.                 Copying_backgroundworker.ReportProgress(f)
    22.             Next
    23.             For Each Fullpath_d As String In sFolders
    24.                 .CopyDirectory(Fullpath_d, GameFolder, overwrite:=True)
    25.                 b += 1
    26.                 Foldercounter += 1
    27.                 Me.lblUnpacked.Invoke(New lblUnpacked_Delegate_Invoker(AddressOf lblUnpacked_Invoker), "Copying folder " & IO.Path.GetDirectoryName(Fullpath_d))
    28.                 d = (100 * b / sFolders.Length)
    29.                 Copying_backgroundworker.ReportProgress(f)
    30.             Next
    31.         End With
    32.     End Sub
    33.  
    34.     Private Sub Copying_backgroundworker_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles Copying_backgroundworker.ProgressChanged
    35.         ProgressBar1.Value = e.ProgressPercentage
    36.         ProgressBar1.Refresh()
    37.     End Sub
    38.  
    39.     Private Sub Copying_backgroundworker_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles Copying_backgroundworker.RunWorkerCompleted
    40.         Me.lblProgress.Invoke(New lblProgress_Delegate_Invoker(AddressOf lblProgress_Invoker), "Done copying...")
    41.     End Sub
    Last edited by youngbucks; Oct 22nd, 2008 at 07:25 PM.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [2008] backgroundworker not reporting progress

    You're calling ReportProgress on rar_decompression_worker and handling the ProgressChanged event of Copying_backgroundworker. Do those two variables refer to the same object? Given your issue, I'll wager not. This is one reason why they recommend that you always use the sender in the event handlers to refer to the BackgroundWorker object.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: [2008] backgroundworker not reporting progress

    lmao jmcilhinney thanks man i didnt realize that.. this is telling me 1am in the morning is a bit too late to be doing this, and u still havent changed..... love it But sadly, changing that did nothing I changed that and the progressbar doesnt move and the label doesnt report the file its copying either but if i go to the folder the files and folders are copying fine.
    Last edited by youngbucks; Oct 22nd, 2008 at 07:21 PM.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [2008] backgroundworker not reporting progress

    You're passing 'f' to ReportProgress. 'f' is initialised to 0 and I don't see where you're changing its value, so you're setting the progress to 0 all the time.

    As for your Label, the first thing to note is that there's no need for a delegate in the RunWorkerCompleted event handler. It's executed in the UI thread, which is the whole point. You should simply be setting the Label's Text directly.

    I would also recommend using the ReportProgress/ProgressChanged members to update the Labels with the file names, etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width