On 14 Jul 2004 13:08:15 +0200,
hi***************@gmx.at (Herfried K. Wagner
[MVP]) wrote:
You /must not/ access instance members of Windows Forms forms/controls
Thanks again. The bit of extra code below, idea stolen from one of the
links you posted, did it.
It's much more than necessary in this simple example, but in this form it
can be called from anywhere - it calls itself back in the right thread if
necessary.
Funny that InvokeRequired isn't shown by intellisense, but it's documented
and it works--or does that mean there's yet another pitfall?
Private Delegate Sub d_SetLabelVisibility(ByVal State As Boolean)
Private Sub SetLabelVisibility(ByVal State As Boolean)
If Label1.InvokeRequired Then
Dim delg As New d_SetLabelVisibility(AddressOf SetLabelVisibility)
Label1.Invoke(delg, New Object() {State})
Else
Label1.Visible = State
End If
End Sub
Private Sub ThreadProc()
SetLabelVisibility(True)
Thread.Sleep(250)
SetLabelVisibility(False)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
SetLabelVisibility(Not Label1.Visible)
Debug.WriteLine(Label1.Visible)
End Sub