using (TcpClient tcp = new TcpClient())   
{   
    IAsyncResult ar = tcp.BeginConnect("127.0.0.1", 80, null, null);   
    System.Threading.WaitHandle wh = ar.AsyncWaitHandle;   
    try  
    {   
       if (!ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5), false))   
       {   
           tcp.Close();   
           throw new TimeoutException();   
       }   
  
        tcp.EndConnect(ar);   
    }   
    finally  
    {   
        wh.Close();   
    }   
}  

相关文章:

  • 2021-11-29
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-26
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2021-12-08
相关资源
相似解决方案