I've got a listview control on the main form. I've also got a webserver running. Here's the webserver class's relevant code:
Public Function start(ipAddress As IPAddress, port As Integer, maxNOfCon As Integer, contentPath As String) As Boolean
If running Then
Return False
End If
Try
serverSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
serverSocket.Bind(New IPEndPoint(ipAddress, port))
serverSocket.Listen(maxNOfCon)
serverSocket.ReceiveTimeout = timeout
serverSocket.SendTimeout = timeout
running = True
Me.contentPath = contentPath
Catch
Return False
End Try
Dim requestListenerT As New Thread(AddressOf first)
requestListenerT.Start()
Return True
End Function
Function second(clientSocket As Socket)
'clientSocket.ReceiveTimeout = timeout
'clientSocket.SendTimeout = timeout
End Function
Function first()
While running
Dim clientSocket As Socket
Try
clientSocket = serverSocket.Accept()
Dim requestHandler As New Thread(AddressOf second)
Try
handleTheRequest(clientSocket)
Catch
Try
clientSocket.Close()
Catch
End Try
End Try
requestHandler.Start()
Catch
End Try
End While
End Function
The problem is, the code inside the function handleTheRequest doesn't update the listview control on the form.
Private Sub handleTheRequest(clientSocket As Socket)
'...
'if xxx data comes in then frm_Main.lstview.items.add(xxxx)
end sub
Could you tell me why this is happening? I suspect it's got something to do with the fact that I'm using threads.