IAsyncResult ar = tcpClient.BeginConnect(ip,port,null,null);
bool success = ar.AsyncWaitHandle.WaitOne(1000);
if (!success)
throw new Exception(“超时时间已到,未连接到指定服务器”);
C# TcpClient的Connect超时处理(Timeout)
最新推荐文章于 2024-07-17 21:12:24 发布
IAsyncResult ar = tcpClient.BeginConnect(ip,port,null,null);
bool success = ar.AsyncWaitHandle.WaitOne(1000);
if (!success)
throw new Exception(“超时时间已到,未连接到指定服务器”);