Updating controls on a form

Kelly Baker <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <005e01c76e86$8136be30$83a43a90$@com>
Unless my app is EXTREMELY simple, I get the cross-threading error message
regularly when updating controls on a Windows form.

My latest example involves a dll that runs a System.Threading.Timer,
updating private shared variables.  When it finishes updating, it raises a
NewData event.  My app responds to that event by updating display controls
(labels in this case).  I have to use a delegate and update them like this:

Private Sub SetText(ByVal [text] as String)
    If Me.Messages.InvokeRequired Then
        Dim d as New SetTextCallBack(AddressOf SetText)
        Me.Invoke(d, New Object() {[text]})
    Else
        Me.Messages.Text = [text]
    End If
End Sub

I have to write a different routine like this for each control on the form
that I want to update.  Is there a better way?  Please?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.