作者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/cn.aspx?n=bbs/Visual_Basic/M.1464148315.A.651.html
※ 编辑: Xavier (61.221.47.106), 05/25/2016 11:53:59