Reputation: 1069
If i use: Label1.Invoke(Sub() Label1.Text = "Test")
this updates successfully however, if i try do: Txt_Response.Invoke(Sub() Txt_Response.Text = "Test")
the text only updates after the rest of the code has executed and the thread is free.
Is there an easy way to accomplish this without any extra load?
Upvotes: 0
Views: 294
Reputation: 1069
I didnt want to do the long way but i guess i needed it done!
Basically the fix is below, i have added the ability to provide controls so its dynamic to everything but for the sake of this question, i will provide it for textbox.
Private Delegate Sub ResponseUpdateEventHandler(ByVal message As String)
Private Sub UpdateResponseBox(ByVal message As String)
If Txt_Response.InvokeRequired Then
Txt_Response.Invoke(New ResponseUpdateEventHandler(AddressOf UpdateResponseBox), New Object() {message})
Else
Txt_Response.AppendText(message + Environment.NewLine)
End If
End Sub
Then just call using: UpdateResponseBox("Connecting to device, Please wait...")
Upvotes: 1