关闭窗体时,怎样结束Receive方法的阻塞?
答案是自己给自己发一个消息,随便什么内容。
Console.WriteLine("等待连接...");
byte[] bytes = listener.Receive(ref RemoteIpEndPoint);
UdpClient udpClient = new UdpClient(4444);
udpClient.Connect("127.0.0.1", 8888);
string msg = "1";
Byte[] bytes = Encoding.ASCII.GetBytes(msg);
udpClient.Send(bytes, bytes.Length);