title: TCP Automatic Reconnect (Forever until user tells it to stop)
body: <p>I have a way to tell the TCP client to connect over and over if a bool is true, but i don´t know if this really is a good way to do it, as i pretty much tells it to to it over and over, and ignore the errors.</p>
  
  <p>But i also don´t know of any other way to do it.</p>
  
  <p>But maybe you guys do, here is the part of the code:</p>
  
  <pre><code> while (capcon == true)
      {
  
          using (tcp = new TcpClient())
          {
              tcp.NoDelay = true;
              try
              {
                  if (!tcp.Connected)
                      tcp.Connect(adress);
              }
              catch (Exception e)
              {
                  if (e is SocketException || e is IOException) { }
                  else
                      MessageBox.Show(e.Message + " Tcp Connect : Send");
  
              }
              using (var ms = new MemoryStream())
              {
                  Stoptimer = new Stopwatch();
                  int i = 0;
                  while (tcp.Connected &amp;&amp; capcon == true)
                  {
                      try
                      {
                          FastMethods.CaptureBitBit(hwnd, JpegParam, jpeg, ms);
                          if (bsize != ms.Length &amp;&amp; tcp.Connected)
                          {
                              bsize = ms.Length;
                              Stoptimer.Start();
  
                              tcp.GetStream().Write(BitConverter.GetBytes(bsize), 0, intsize);
  
                              tcp.GetStream().Write(ms.GetBuffer(), 0, (int)bsize);
                              //i++;
                              //tcp.GetStream().Write(rv, 0, rv.Length);
                              if (i &gt; 100)
                              {
                                  i = 0;
                                  Stoptimer.Stop();
                                  Console.WriteLine(Stoptimer.ElapsedTicks);
                                  Stoptimer = new Stopwatch();
                              }
  
                          }
                          ms.SetLength(0);
  
                      }
  
                      catch (Exception e)
                      {
                          if (e is SocketException || e is IOException)
                          {
                              break;
                          }
                          else
                          {
                              MessageBox.Show(e.Message + ": Send Error");
                          }
                      }
                  }
              }
          }
      }
  </code></pre>
  
  <p>Well, as you can see, it´s a mess, but it´s what i got.</p>