-
Oct 22nd, 2008, 06:52 PM
#1
Thread Starter
Hyperactive Member
[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:
Private Sub Copying_backgroundworker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Copying_backgroundworker.DoWork With My.Computer.FileSystem Me.lblProgress.Invoke(New lblProgress_Delegate_Invoker(AddressOf lblProgress_Invoker), "Copying files...") Dim sFiles As String() = IO.Directory.GetFiles(WorkingPatchDir) Dim sFolders As String() = IO.Directory.GetDirectories(WorkingPatchDir) Dim Amountoffoundfiles As Integer = IO.Directory.GetFiles(WorkingPatchDir).Count Dim Amountoffoundfolders As Integer = IO.Directory.GetDirectories(WorkingPatchDir).Count Dim Filecounter As Integer Dim Foldercounter As Integer Dim a As Integer = 0 Dim b As Integer = 0 Dim c As Integer = 0 Dim d As Integer = 0 Dim f As Integer = c + d For Each Fullpath As String In sFiles File.Copy(Fullpath, Path.Combine(GameFolder, Path.GetFileName(Fullpath)), overwrite:=True) a += 1 Filecounter += 1 Me.lblUnpacked.Invoke(New lblUnpacked_Delegate_Invoker(AddressOf lblUnpacked_Invoker), "Copying file " & IO.Path.GetFileName(Fullpath)) c = (100 * a / sFiles.Length) Copying_backgroundworker.ReportProgress(f) Next For Each Fullpath_d As String In sFolders .CopyDirectory(Fullpath_d, GameFolder, overwrite:=True) b += 1 Foldercounter += 1 Me.lblUnpacked.Invoke(New lblUnpacked_Delegate_Invoker(AddressOf lblUnpacked_Invoker), "Copying folder " & IO.Path.GetDirectoryName(Fullpath_d)) d = (100 * b / sFolders.Length) Copying_backgroundworker.ReportProgress(f) Next End With End Sub Private Sub Copying_backgroundworker_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles Copying_backgroundworker.ProgressChanged ProgressBar1.Value = e.ProgressPercentage ProgressBar1.Refresh() End Sub Private Sub Copying_backgroundworker_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles Copying_backgroundworker.RunWorkerCompleted Me.lblProgress.Invoke(New lblProgress_Delegate_Invoker(AddressOf lblProgress_Invoker), "Done copying...") End Sub
Last edited by youngbucks; Oct 22nd, 2008 at 07:25 PM.
-
Oct 22nd, 2008, 07:10 PM
#2
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.
-
Oct 22nd, 2008, 07:15 PM
#3
Thread Starter
Hyperactive Member
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.
-
Oct 22nd, 2008, 07:42 PM
#4
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.
Last edited by jmcilhinney; Oct 22nd, 2008 at 07:45 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|