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