Ciao a tutti, sto creando un programmino con VB.Net 2008 nel quale ho un sul form principale un datagridview che dovrebbe essere aggiornato da un thread separato che riceve i dati trammite un socket tcp...
sul form principale ho il seguente codice
invece sulla classe Socket che viene lanciata su un'altro thread riceve dei messaggi dal socket tcp e trammite il codice:
Public Sub Start()
Try
Server = New TcpListener(LocalAddr, Port)
Server.Start()
While True
Console.Write("Waiting for a connection... ")
Dim client As TcpClient = Server.AcceptTcpClient()
Console.WriteLine("Connected!")
RaiseEvent Connected()
data = Nothing
' Get a stream object for reading and writingd
Stream = client.GetStream()
Dim i As Int32
' Loop to receive all the data sent by the client.
i = stream.Read(bytes, 0, bytes.Length)
While (i <> 0)
' Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
Console.WriteLine("Received: {0}", data)
Form1.DGV_AddRow(data)
i = stream.Read(bytes, 0, bytes.Length)
End While
client.Close()
End While
Catch ex As SocketException
Console.WriteLine("SocketException: {0}", ex)
Finally
Server.Stop()
End Try
Console.WriteLine(ControlChars.Cr + "Hit enter to continue....")
Console.Read()
End Sub
Apparentemente tutto ok, ma mentre nella console ho la conferma della ricezione del messaggio nel Datagridview1 presente sul form principale rimane sempre vuoto....
Ringrazio anticipatamente per la vostra disponibilità
Luca