独立线程上的异步套接字侦听器-VB.net
我正在尝试使用来自Microsoft的代码进行异步套接字连接。侦听器似乎在锁定GUI的主线程中运行。我对套接字连接和多线程都是新手。我很难一下子把这件事想清楚 使用的代码位于 使用此示例,如何将侦听器移动到自己的线程?独立线程上的异步套接字侦听器-VB.net,vb.net,multithreading,sockets,asynchronous,tcp,Vb.net,Multithreading,Sockets,Asynchronous,Tcp,我正在尝试使用来自Microsoft的代码进行异步套接字连接。侦听器似乎在锁定GUI的主线程中运行。我对套接字连接和多线程都是新手。我很难一下子把这件事想清楚 使用的代码位于 使用此示例,如何将侦听器移动到自己的线程? Public Shared Sub Main() ' Data buffer for incoming data. Dim bytes() As Byte = New [Byte](1023) {} ' Establish the local endp
Public Shared Sub Main()
' Data buffer for incoming data.
Dim bytes() As Byte = New [Byte](1023) {}
' Establish the local endpoint for the socket.
Dim ipHostInfo As IPHostEntry = Dns.GetHostEntry(Dns.GetHostName())
Dim ipAddress As IPAddress = ipHostInfo.AddressList(1)
Dim localEndPoint As New IPEndPoint(ipAddress, 11000)
' Create a TCP/IP socket.
Dim listener As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
' Bind the socket to the local endpoint and listen for incoming connections.
listener.Bind(localEndPoint)
listener.Listen(100)
您可以简单地以异步方式调用套接字的Main方法。您可以使用:
Call New Action(AddressOf _
AsynchronousSocketListener.Main).BeginInvoke(Nothing, Nothing)
或:
(或使用)看起来很有用!我想这甚至有助于我理解它。
Call New Threading.Thread(AddressOf AsynchronousSocketListener.Main).Start()