I'm have made an asynchronous client/server program using sockets. I am trying to update a listbox when i receive a message but i keep getting an TargetInvocationException on it. I have the method i am using for this on other controls and they work just fine, its just this listbox. What happens is when the server recieves data on a socket it is stored to sokData. If sokData begins with the string "Client-List" it will proceed to remove the old clientlist and enter the newclientList listbox but when i try to remove the items after jumping to removeClientListUpdate i get a TargetInvocationError. I dont have many ideas as to why this happens since i am a noob at threading and delegates. Hope you can get what i am trying to do and help me out. If i need to post more info let me know otherwise, here is my code.
Thanks for the help!!
Public Delegate Sub removeClientListCallback()
public sub ....
....
If sokData.StartsWith("CLIENT-LIST") Then
If clientList.InvokeRequired Then
clientList.BeginInvoke(New removeClientListCallback(AddressOf removeClientListUpdate), nothing)
Else
removeClientListUpdate()
End If
....
....
end sub
Private Sub removeClientListUpdate()
Try
clientList.Items.Clear()
clientList.Update()
Catch e As Exception
End Try
End Sub
Thanks for the help!!
Public Delegate Sub removeClientListCallback()
public sub ....
....
If sokData.StartsWith("CLIENT-LIST") Then
If clientList.InvokeRequired Then
clientList.BeginInvoke(New removeClientListCallback(AddressOf removeClientListUpdate), nothing)
Else
removeClientListUpdate()
End If
....
....
end sub
Private Sub removeClientListUpdate()
Try
clientList.Items.Clear()
clientList.Update()
Catch e As Exception
End Try
End Sub