- Code: Select all
int timeout = 2000; // Deux secondes
TcpClient tcp = new TcpClient();
IAsyncResult iar = tcp.BeginConnect(iphote, port, null, null);
bool success = iar.AsyncWaitHandle.WaitOne(timeout, true);
if (!success)
{
tcp.Close();
// Traitement supplémentaire
}
// Succès
tcp.EndConnect(iar);
// Traitement supplémentaire
tcp.Close();
