Salve,
Ho un problema con i thread:
ho eseguito questo piccolo esempio:
codice:Private Sub bottone1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bottoneConnetti.Click Try 'Declare a Thread and Assign it to a Methord Hi Dim t As New Thread(AddressOf tr1) 'Declare Another Thread and assign it to Bye Dim b As New Thread(AddressOf tr2) 'Set the priority level for each thread t.Priority = ThreadPriority.Normal b.Priority = ThreadPriority.Lowest 'Start the thread execution t.Start() b.Start() Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Public Sub tr1() Do While True txtBox1.Text += "prova1" Loop End Sub Public Sub tr2() Do While True txtBox2.Text += "prova2" Loop End Sub
Mi restituisce come errore "Cross-thread operation not valid: Control 'txtBox1 accessed from a thread other than the thread it was created on."
Come mai?
Come posso risolvere?
![]()