作者Xavier (X.avi(er))
看板Visual_Basic
標題[.NET] textbox 內容未更新?
時間Wed May 25 11:51:53 2016
大家好!
我開了一個 thread-S 監聽有無 client連入,
當有 client連入時, textbox印出 "client no.? 連入",
並開一個 thread-C 處理資料的傳送接收。
code片段如下:
Private Sub btOpenServer_Click()
Dim ListenThread As New Thread(AddressOf StartListen)
ListenThread.IsBackground = True
ListenThread.Start()
End Sub
Private Sub StartListen()
UpdateText("Server started at: " + serverIP.ToString() + ":" +
Port + ".", "on")
While True
linkCount += 1
ClientSocket = serverSocket.Accept()
UpdateText("Client No:" + Convert.ToString(linkCount) + "
started!", "on")
>>>此時 textbox顯示 Client No:1 started!<<<
Dim client As New handleClinet
client.startClient(ClientSocket, Convert.ToString(linkCount))
End While
End Sub
>>> 以下是另一個 .vb檔 <<<
Module HandleClient
Public Class handleClinet
Public Sub startClient(ByVal inClientSocket As Socket, ByVal clineNo As
String)
Dim ctThread As Threading.Thread = New Threading.Thread(AddressOf
doChat)
ctThread.Start()
End Sub
Private Sub doChat()
Dim networkStream As New NetworkStream(clientSocket)
networkStream.Read(bytesFrom, 0,
CInt(clientSocket.ReceiveBufferSize))
dataFromClient = System.Text.Encoding.ASCII.
GetString(bytesFrom)
************** Form1.UpdateText("From client-" + dataFromClient)
>>>此時 textbox依然只有顯示 Client No:1 started!<<<
>>>並未顯示 From client-?????????? <<<
End Sub
End Class
End Module
請問,為什麼 ***那行把資料傳回去時,textbox並未更新
"From client-" + dataFromClient 該行資料呢?
我下中斷去看,textbox的資料是有改變的,
但是實際上看到的卻是沒變的。
感謝賜教!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.221.47.106
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Visual_Basic/M.1464148315.A.651.html
※ 編輯: Xavier (61.221.47.106), 05/25/2016 11:53:59