Hi,
I am trying out some code from a book called network programming
For UDP messaging
The only thing is, I get a thread not safe error
The solution from F1 Help is not really applicable because it uses outdated code (SetTextCallback)
I know I need to call the same method again, but on the thread the control is created on.
It also mentioned delegates briefly, so I will look at that in the meantime
this is what I am dealling with know
I am trying out some code from a book called network programming
For UDP messaging
The only thing is, I get a thread not safe error
The solution from F1 Help is not really applicable because it uses outdated code (SetTextCallback)
I know I need to call the same method again, but on the thread the control is created on.
It also mentioned delegates briefly, so I will look at that in the meantime
this is what I am dealling with know
VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Label2.Text = CStr(Me.Handle)
Dim thdUDPServer = New Thread(New ThreadStart(AddressOf ServerThread))
thdUDPServer.start()
End Sub
Public Sub ServerThread()
Dim udpClient As New UdpClient(8080)
While True
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Dim receiveBytes As Byte()
receiveBytes = udpClient.Receive(RemoteIpEndPoint)
Dim ReturnData As String = Encoding.ASCII.GetString(receiveBytes)
If (Me.lbConnections.InvokeRequired) Then
[COLOR="SeaGreen"]' need to do the right stuff here[/COLOR]
Dim d As New ContextCallback(AddressOf ???)
Me.Invoke(d, New Object)
Else
lbConnections.Items.Add(RemoteIpEndPoint.Address.ToString() + ":" + ReturnData.ToString)
End If
End While
End Sub
Last edited: