title: TCP client connection freezes program
body: <p>I'd like to have an asynchronous continuous ping request on a ip + port.
  The problem is, when the targeted server is offline, the whole program freezes during request time. But this shouldn't happen.</p>
  
  <p>This is my ping function which is called once when starting the program.
  It should do a ping request every 3 seconds.</p>
  
  <pre><code>    public async void Start(string ip)
      {
          Stopwatch watch = new Stopwatch();
  
          while (true)
          {
              watch.Restart();
              using (TcpClient tcp = new TcpClient())
              {
                  //try to connect to a closed port
                  IAsyncResult res = tcp.ConnectAsync("127.0.0.1", 1234);
  
                  //during the following while-loop the whole program freezes
                  //although this is an asynchronous function
                  while (watch.ElapsedMilliseconds &lt; 1000) 
                  {
                      if (tcp.Connected)
                      {
                          break;
                      }
                  }
                  watch.Stop();
                  if (tcp.Connected)
                  {
                      StatusControl.Text = watch.ElapsedMilliseconds.ToString() + " ms";
                  }
                  else
                  {
                      StatusControl.Text = "Offline";
                  }
              }
              //wait 3secs for the next request
              await Task.Delay(3000);
          }
      }
  </code></pre>