The TcpClient
constructor attempts to connect to the server that is listening on the specified port. But this process has a timeout of 1 minute. If the connection do not succeed within 1 minute, it will be closed and an exception will be thrown; hence you are getting the exception.
This is the only way to attempt to connect to server. The only thing you can add is cause the thread to sleep (Thread.Sleep(n)
) for some time, like 10 seconds or so (depending on your context).