title: Socket.Connect Throws and Error I can't catch
body: <p>I apologize if this has been answered on SO. I looked but didn't find it. My situation is my customer can connect to their TCP server either by being on the local network, or coming in remotely via a Verizon modem. (I am using .NET 3.5 - C#)</p>
  
  <p>When I connect from either of those, things are fine. But what if I am accidentally on the "wrong" network (ex: I am at Starbucks and logged onto their wireless network. I forget, thinking I am on the Verizon card, so, now I try to log in) The server refuses the connection. Fine. But my Try/Catch is not catching anything... it simply exits the routine (if I am calling it through threadpool) or it hangs if I call it directly.</p>
  
  <p>Here is the code (it fails on: m_clientSocket.Connect(ipEnd) ):</p>
  
  <pre><code>tcpConnectionObject passedTCPObject = (tcpConnectionObject) obj;
  if (checkNetStat(passedTCPObject) == false)
  {
       updateStatus(false);
       return;
  }
  
  try
  {
       m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
       IPAddress ip = IPAddress.Parse(passedTCPObject.ipString);
       int iPortNo = System.Convert.ToInt16(passedTCPObject.portString);
       IPEndPoint ipEnd = new IPEndPoint(ip, iPortNo);
  
       m_clientSocket.Connect(ipEnd);
       if (m_clientSocket.Connected)
       {
            updateStatus(true);
            //Wait for data asynchronously 
            WaitForData();
       }
  }
  catch (SocketException e)
  {
       updateStatus(false);
       return;
  }
  catch (Exception e)
  {
       updateStatus(false);
       return;
  }
  
  updateStatus(true);
  return ;
  </code></pre>
  
  <p>I call this from a Winform using the threadpool:</p>
  
  <pre><code>tcpConnectionObject passObject = new tcpConnectionObject(serverIP, serverPORT);
          ThreadPool.QueueUserWorkItem(new WaitCallback(SRVR_CONNECT.connectToTCP), passObject);
  </code></pre>
  
  <p>This is called in the form's SHOW() method. When I do it like this, my form shows, but the status is never changed (which it should be by any result) If I put a debugger on it, and start stepping through the execution, I get to the Socket.Connect() and the debugger simply exits the mthod, and my form shows. I never hit any of my catches.</p>
  
  <p>I have tried every error that Socket can generate, but it never catches anything. When I run my debugger, as soon as I hit that line, it exits my method, but there is no error that is catch-able.</p>