Hi all,
I've been working on implementing a backgroundworker into my program to help speed up the initial loading of the app. It has about 50 controls on the form and worked it out where I have all UI changes going in the progressChanged function of the BGW.
I thought all was fine and dandy till I set the property to check for illegalThreadCalls and put the app into debug and found out that anything I call in the doWork function throws me that error.
I thought of creating delegates for all the components so I tried just one to see if I needed to invoke the thread but it's throwing the Cross-thread operation not valie error just while trying to check if I need to invoke the thread. WHat is going on? I did everything right, I thought I was following every rule with this :)
Original:
Modified to check if it's the ReportProgress function causing it.
I've been working on implementing a backgroundworker into my program to help speed up the initial loading of the app. It has about 50 controls on the form and worked it out where I have all UI changes going in the progressChanged function of the BGW.
I thought all was fine and dandy till I set the property to check for illegalThreadCalls and put the app into debug and found out that anything I call in the doWork function throws me that error.
I thought of creating delegates for all the components so I tried just one to see if I needed to invoke the thread but it's throwing the Cross-thread operation not valie error just while trying to check if I need to invoke the thread. WHat is going on? I did everything right, I thought I was following every rule with this :)
Original:
Code:
<DoWork>
BackgroundWorker1.ReportProgress(0, "Tom")
<ProgressChanged>
Dim value As String = DirectCast(e.UserState, String)
Select Case e.ProgressPercentage
Case 0
lblPriNameVal.Text = value
lblPriNameVal.Visible = True
End If
Code:
IF me.InvokeRequired Then
Dim d As New UpdatePrimaryName(AddressOf UpdatePrimaryNameHandler)
Me.Invoke(d, New Object() {"Tom"})
End If