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.
Can someone please help me out?
Starting / opening threads:
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");
}
Then my attempt at closing them:
void OnApplicationQuit()
{
try
{
clientThread.Abort();
tcp_listener.Stop();
listen_thread.Abort();
}
catch(Exception e)
{
Debug.Log(e.Message);
}
}
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.