请问怎么让收到字符1重新延迟或计时,就是 System.Threading.Thread.Sleep(5000);没有执行完又收到一个字符1,后面代码不执行, System.Threading.Thread.Sleep(5000); 重新计时[C#] 纯文本查看 复制代码 static void Main(string[] args)
{
int recv;
byte[] revData = new byte[1024];
byte[] sendData = new byte[1024];
IPEndPoint ip = new IPEndPoint(IPAddress.Any, 8421);
Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
newsock.Bind(ip);
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint Remote = (EndPoint)(sender);
while (true)
{
sendData = new byte[1024];
recv = newsock.ReceiveFrom(sendData, ref Remote);
string recvData = string.Format(Encoding.Default.GetString(sendData, 0, recv));
//收到字符1发送给客户端
if ("1".Equals(recvData))
{
UdpClient dqkUdp = new UdpClient(0);
//数据men
byte[] men = { 0xCA, 0x20, 0xF0, 0x18, 0x02, 0x03, 0x00, 0xAC };
dqkUdp.Connect("192.168.xxx.xxx", xxxx);
//延迟5秒(计时)
System.Threading.Thread.Sleep(5000);
dqkUdp.Send(men, men.Length);
dqkUdp.Close();
}
}
} |