Access controls

Errods

Well-known member
Joined
Dec 17, 2007
Messages
71
Location
Kundapur, Karnataka, Udupi, India.
Programming Experience
1-3
hi Guys,,


When i try to access any of the UI Objects of a form from a thread i get an error.......

Say i want to change the text property of a label in Form 1 from a thread which begins the instance i load form 1(i.e. Form1_Load event) how do i do it....................
 
You have to use the standard safe code pattern, using a delegate invoked on UI thread.
VB.NET:
Private Sub thethreadmethod()
    Label1.Invoke(d, "the text")
End Sub

Private d As New safesettext(AddressOf settext)
Private Delegate Sub safesettext(ByVal txt As String)

Private Sub settext(ByVal txt As String)
    Label1.Text = txt
End Sub
 
Back
Top