IAsyncResult ar = tcpClient.BeginConnect(ip,port,null,null);
bool success = ar.AsyncWaitHandle.WaitOne(1000);
if (!success)
throw new Exception("超时时间已到,未连接到指定服务器");

 

重点就是使用BeginConnect方法,及IAsyncResult.AsyncWaitHandle.WaitOne方法 

 

具体怎么定义的就不写了。

 



 

相关文章:

  • 2021-09-27
  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-08-07
  • 2021-09-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2021-09-25
  • 2021-08-13
相关资源
相似解决方案