我想在vb.net多线程中调用模块中的自定义函数---网络通讯----没有返回值
在线程中的代码是Protected Sub processrequest()
'Dim curthread As Thread
'Dim aaa As New ListBox
curthread = System.Threading.Thread.CurrentThread
Dim cursocket As Socket
Dim ip1 As IPEndPoint
Dim aa As String
cursocket = listener.AcceptSocket
ip1 = cursocket.RemoteEndPoint
SyncLock curthread
aa = getaddr(cursocket)
ListBox1.Items.Add(ip1.Address.ToString & " " & aa)
End SyncLock
cursocket.Close()
End Sub
在模块中定义的函数为
Public Function getaddr(ByVal client1 As Socket) As String
'SyncLock GetType(xieyi)
Dim bytes As Integer
Dim buffer(100) As Byte
Dim sendbytes(2) As Byte
Dim temp As String
'getaddr = ""
sendbytes(0) = &HE7
sendbytes(1) = &H1
sendbytes(2) = &H4
'client1 = listener.AcceptSocket
Try '######################错误处理
client1.Send(sendbytes, sendbytes.Length, 0)
While listening
'If client1.Available > 0 Then
client1.Receive(buffer, buffer.Length, 0)
temp = Encoding.UTF8.GetString(buffer)
getaddr = temp
listening = False
'End If
End While
Catch ex As System.Exception
getaddr = ""
End Try
'client1.Close()
'End SyncLock
End Function
--------------------编程问答-------------------- 可能要本就没连上 --------------------编程问答-------------------- 可以连上,我在模块中设置了断点,程序可以运行到那
补充:.NET技术 , VB.NET