I have been using the VB.net backgroundwork component on a couple programs that check files or delete files where I report the current work back to the UI though backgroundwork1_reportprogress. The worker class is setup like this
CODE
Public Class CurrentJob
Public Class CurrentWorkState
Public CurrentWork As String
Public Dirwork As String
End Class
Other code
EndClass
I then set the data for CurrentWork in the work class like this
CODE
Dim State As New CurrentWorkState
State.CurrentWork = "Starting"
State.Dirwork = "Starting"
Worker.ReportProgress(0, State)
I then pickup the changes to currentwork in progressChanged and display the current data that I have passed normally the current file that is being copied or deleted. Code as follows
CODE
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Dim state As CurrentJob.CurrentWorkState = CType(e.UserState, CurrentJob.CurrentWorkState)
Me.lblcurrprogress.Text = state.CurrentWork.ToString
'Me.lbldirworktext.Text = state.Dirwork.ToString
End Sub
As you can see I also pass some information to the UI via the DirWork and display the information in a different label. My problem is that when I add this line off code in after a short period off time (I would say the first time the progress changed tries to update the second label), an execption is thorwn, the exception is "System.Reflection.TargetOnvocationException" exception has been thrown by the target of an invocation. The innerexecption is "Object reference not set to an instance of an object" and this is the stack trace from the inner exception "at Synchierarchies.frmsynchierarchies.BackgroundWorker1_ProgressChanged(Object sender, ProgressChangedEventArgs e) in E:\\Sync Hierarchies\\DeleteFiles\\frmsync1.vb:line 81\r\n at System.ComponentModel.BackgroundWorker.OnProgressChanged(ProgressChangedEventArgs e)\r\n at System.ComponentModel.BackgroundWorker.ProgressReporter(Object arg)".
Can any see where I have gone wrong or what is going wrong?