Quantcast
Channel: cross-thread UI updating?
Viewing all articles
Browse latest Browse all 12

cross-thread UI updating?

$
0
0
Hmya, you're struggling but it's a Good Thing.  To get your code to compile, recode the BeginInvoke() method like this:

      Me.BeginInvoke(New System.EventHandler(AddressOf UpdateUI), EventArgs.Empty)

I'm using "Me" instead of "statusLabel".  Both work, both are Windows Forms object that were created on another thread.  Using the form instance instead of the control instance make (just a bit) more sense.

You are already using MethodInvoker.  But then switch to EventHandler without passing anything useful.  To stay consistent, you could do it like this instead:

    Dim mi As MethodInvoker = New MethodInvoker(AddressOf FillMyData)
    mi.BeginInvoke(Nothing, Nothing)
...
  Private Sub FillMyData()
    '... Do your stuff
    Me.BeginInvoke(New MethodInvoker(AddressOf UpdateUI))
  End Sub
  Private Sub UpdateUI()
    '... etc
  End Sub

All of this ugliness would easily be avoided if you used the BackgroundWorker class.  Instead of handing the code on a plate, I'll let you figure it out by yourself.  Good Thing and all that.  Yell when you've thought about it for a while and got stuck.

Viewing all articles
Browse latest Browse all 12

Trending Articles



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