title: Closing threads in Unity with C#
body: <p>I'm wanting to make sure that when my application quits that any and all open threads are closed. However when I try to do so I get the error telling me that there is no reference object for what I'm trying to do, even though it's all in the same class. </p>
  
  <p>Can someone please help me out?</p>
  
  <p>Starting / opening threads:</p>
  
  <pre><code>Thread listen_thread;
  TcpListener tcp_listener;
  Thread clientThread;
  
  
  // Use this for initialization
  void Start () 
  {
      IPAddress ip_addy = IPAddress.Parse(ip_address);
      tcp_listener = new TcpListener(ip_addy, port);
      listen_thread = new Thread(new ThreadStart(ListenForClients));
      listen_thread.Start();
  
  
      Debug.Log("start thread");
  
  }
  </code></pre>
  
  <p>Then my attempt at closing them:</p>
  
  <pre><code>void OnApplicationQuit()
  {
      try
      {
          clientThread.Abort();
          tcp_listener.Stop();
          listen_thread.Abort();
  
      }
      catch(Exception e)
      {
          Debug.Log(e.Message);
      }
  }
  </code></pre>
  
  <p>What am I doing wrong? The threads open and do what they are suppose to just fine, but for some reason I can't close them. </p>