Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TargetInvocationException

Status
Not open for further replies.

nerd19

Technical User
Jun 6, 2007
39
US
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
 
That looks like VB.NET code - try forum796

This forum is solely for VB5/6 stuff

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top