title: Most effective way to connect/retry connecting using C#?
body: <p>I am creating a little game client that will end up connecting to a server to gather some information on available games to play, how many players are playing, and all kinds of other stuff that you can imagine it ought to do.</p>
  
  <p>My difficulties come in finding an effective way in dealing with the connect/retry connect sequence upon first loading. </p>
  
  <p>I imagined my client would follow this process in trying to connect:</p>
  
  <ol>
  <li>Client application executed</li>
  <li>Try to establish connection</li>
  <li>If connection successful gather information - If not successful proceed to step 4</li>
  <li>Display a new dialog/form that prompts the user that a connection is trying to be established</li>
  <li>Loop till a connection has been established</li>
  </ol>
  
  <p>I have been questioning my methods in trying to follow this sequence. I question if it is the right/most effective way to connect as well as to why my form I display in step 4 isn't working?</p>
  
  <pre><code>try
  {
      sock.Connect(authenServerEP);
      // Once connected show our main client window
      this.Show();
      // Create the LoginForm once a connection has been established and display
      LoginForm loginForm = new LoginForm();
      loginForm.ShowDialog();
      if (false == loginForm.Visible)
      {
          loginForm.Dispose();
      }
  }
  catch (SocketException firstConnectException)
  {
      // Load retrying connection form
      EstablishingConnectionForm establishingConnectionForm = new EstablishingConnectionForm();                                
      establishingConnectionForm.Show();
  
      bool connected = false;
      // Loop until we are connected
      while (!connected)
      {
          try
          {
              sock.Connect(authenServerEP);
              connected = true;
              establishingConnectionForm.Dispose();
           }
           catch (SocketException retryConnectException)
           {
               // Pass and retry connection
           }
       }
  } // end catch (SocketException firstConnectException)   
  </code></pre>
  
  <p>As you can see I am catching the SocketException that is raised when there is a problem connecting to the server (such as the server isn't running). I then go on to try to continuously loop till a connection is established. I dunno if I ought to be doing it this way. Are there better ways to do this?</p>
  
  <p>Also when I display establishingConnectionForm with Show() it doesn't look like it all of the forms/tools initialize (initialize could be misleading). The Label that is on the form is just shaded out in white as opposed to having its text displayed. Not only that but it seems like I can't select the form/dialog and actually move it around. It sits there with the "Thinking/Working" mouse icon. Now I presume this is because I am looping trying to reconnect and its blocking because of this (I could be wrong on the blocking?). Can this problem be solved with multithreading? If so do I need to multithread? Is there an easier way to show my form/dialog and be able to interact (IE movie it around and close it with the 'X' in the upper right corner) with it while I still try to reconnect?</p>
  
  <p>Thanks a bunch. I really appreciate you reading this post and am grateful for this community. :D</p>