I'm building a program for scanning IP addresses. I built a class that checks the ports of 

a given IP address. I run this class in loop as thread. I obviously blocking the amount of 

thread that can be run in parallel. The problem is that always the thread returns an exit 

code: 259, and after half a minute or so, the program hangs. 

I tried to search in google, forums, and here what the code 259 means. So i found in some 

forums that it simply return code that not meaning any thing. In other forums i see that is 

means that there a problem with using a lot of memory. So i try to use only 2 threads in 

paralel. It still doesnt work. I try to see another methods to work with threads, so i read 

about threads pool, i change the code to use threads pool, but it still not work. I of 

course made sure that in class i dont use global variableas.

Code : 

```
   private void Get_Port_With_Status_Thread_Inventer()
    {

        for (int Thread_Cnt_Get_Port_N_Status = 1; Thread_Cnt_Get_Port_N_Status < IP_Address.Length + 1; Thread_Cnt_Get_Port_N_Status++)
        {

            if (Open_Threads_Port_N_Status_Counter >= Max_Thread_Allowed)
            {
               Thread_Cnt_Get_Port_N_Status--;
               continue;
            }

            Thread New_Port_N_Status_Thread = new Thread(new ParameterizedThreadStart(Get_Port_With_Status_Thread));
            New_Port_N_Status_Thread.Start(Thread_Cnt_Get_Port_N_Status);

            Open_Threads_Port_N_Status_Counter++;
        }

        End_Get_Port_N_Status_Inventer = true;
    }

   private void Get_Port_With_Status_Thread(object Index_On_Array_Obj)
    {

        int Index_On_Array = (int)Index_On_Array_Obj;

        string IP_Address_Str = IP_Address[Index_On_Array - 1];

        IPEndPoint IP_Address_Connect_Data_Base = new IPEndPoint(IPAddress.Parse(IP_Address_Str), 80);

        Socket Socket_IP_Address_Connect_Data_Base = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

        string Ports_Rep_Index = 80.ToString();

        DateTime Current_New_Now_Seconds = DateTime.Now.Date;

        try
        {
            Socket_IP_Address_Connect_Data_Base.Connect(IP_Address_Connect_Data_Base);
            Socket_IP_Address_Connect_Data_Base.Disconnect(true);

            IP_Port[Index_On_Array - 1] = "Port 80 - Live";
        }

        catch (SocketException g)
        {
            IP_Port[Index_On_Array - 1] = "Port 80 - Dead";
        }

        Open_Threads_Port_N_Status_Counter--;
    }

```