title: stop thread listening for TcpClient from another thread c#
body: <p>I'm currently making client/server app in c# forms. The window has Log(text area), command line(text area) and one button. I have problem with closing server(another thread) while it's running.                                                    </p>
  
  <pre><code>    void Server_Thread_Main(object arg)
      {
          TcpClient client;
          Output.Insert_to_LOG_Window("Server initialized at IP: " + IP_ADDR + ":" + PORT);
          while (true)
          {
              client = listener.AcceptTcpClient();
              clients.Add(new C_Client(client, Output, client_ID_iter++));
  
              clients[clients.Count - 1].Start();
          }
  
  
  
  
      }
  </code></pre>
  
  <p>also I have class for processing commands entered to command line. It's called Task_Menager. Each command is processed by new thread For proccesing command it has this function</p>
  
  <pre><code>    void Server_Task_CMD(optargs args)
      {
          bool if_start = false;
  
          foreach(argument arg in args)
          {
              switch (arg.Option)
              {
                  case "-stop":
                      Output.server.Stop_Server(); //&lt;- stopping server
                      break;
                  case "-start":
                      if_start = true;
                      break;
                  case "-IP":
                      Output.server.Set_Server_IP(arg.Value);
                      break;
                  case "-PORT":
                      Output.server.Set_Server_PORT(arg.Value);
                      break;
                  case "-IPP":
                      if (arg.Value.Contains(':') == true)
                          Output.server.Set_Server_Params(arg.Value);
                      else
                          Output.Insert_to_COMMAND_Log("This " + arg.Value + " isn't valid IP:PORT notation!");
                      break;
                  case "-V":
                  case "-VIEW":
                      Output.server.Display_IP_PORT();
                      break;
                  default:
                      Output.Insert_to_COMMAND_Log("Not known command: " + arg.Option + " !");
                      break;
  
  
  
              }
              if(if_start==true)
                  Output.server.Initialize_Server();
  
          }
      }
  </code></pre>
  
  <p>and this function is </p>
  
  <pre><code>    public void Stop_Server()
      {
          if (server_thread.IsAlive == true)
          {
              Output.Insert_to_LOG_Window("Stopping server...");
              server_thread.Interrupt();
              if (!server_thread.Join(2000))
              {
                  server_thread.Abort();
              }
              Output.Insert_to_COMMAND_Log("Server has been stopped!!!");
          }
          else
              Output.Insert_to_LOG_Window("Server isn't running right now!");
  
  
  
      }
  </code></pre>
  
  <p>And the problem is I don't know why the server thread isn't stopping. </p>