private void WaitUntilTimeOut(ConnectionState connectionState)
 {
     Int32 timeout = 0;
     Int32 maxTimeOut = Settings.Instance.PortScanTimeoutSeconds * 1000 / 50; // in seconds not in miliseconds
     while (timeout <= maxTimeOut && !this.CancelationPending && !connectionState.Done)
     {
         Thread.Sleep(50);
         timeout++;
     }
 }
 private void ScanPort(int port)
 {
     try
     {
         using (TcpClient client = new TcpClient())
         {
             var connectionState = new ConnectionState(port, client);
             client.BeginConnect(this.iPAddress, port, new AsyncCallback(this.AttemptConnect), connectionState);
             WaitUntilTimeOut(connectionState);
             client.Client.Close();
         }
     }
     catch (Exception e)
     {
         Logging.Error("Scan Failed", e);
     }
 }