How is it possible to access a control (f. ex. changing the text property of a Label) or a property of any custom object, when the control or custom-object are created in a diffrent thread than the one from where I want to update them?
Here is an example of what does not work :
VB Code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click StartDoWeighings() End Sub Dim Thread As System.Threading.Thread = New System.Threading.Thread(AddressOf Me.ThreadSub) Private Sub StartDoWeighings() If Not Thread.IsAlive Then Thread.Start() End If End Sub Sub ThreadSub() Label1.Text = Date.Now.ToLongTimeString End Sub End Class
And here is the error when the button is clicked :
"Cross-thread operation not valid: Control 'Label1' accessed from a thread other than the thread it was created on."
Thank you very much for any help !
Regards,
Fabian




Reply With Quote