1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| try { // 连接上说明在线,使用AsyncWaitHandle连接,超时300ms var client = new TcpClient(); var result = client.BeginConnect(dev.RFIDIP, CHostConfig.RFIDPort, null, null); var ret = result.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(300)); if (ret) // 连接上,更新时间戳 { client.EndConnect(result); dev.RFIDIPTime = Utils.GetTimeStampString(); } else { //Console.WriteLine($"connect {dev.RFIDIP} ret: {ret}"); } } catch (Exception e) { //Console.WriteLine(e); }
|