Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27389

VS 2008 Getting Cross-thread operation not valid error even while calling invokerequired [BGW

$
0
0
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:
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

Modified to check if it's the ReportProgress function causing it.
Code:

IF me.InvokeRequired Then
 Dim d As New UpdatePrimaryName(AddressOf UpdatePrimaryNameHandler)
Me.Invoke(d, New Object() {"Tom"})
End If


Viewing all articles
Browse latest Browse all 27389

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>