I have this code in a separate thread (Task) that starts first when the application starts and should not end before the application closes:
TcpListener tcpListener = new TcpListener(IPAddress.Any, port); tcpListener.Start(); while (true) { TcpClient client = tcpListener.AcceptTcpClient(); Task.Factory.StartNew(HandleClientCommunication, client); }
In this case, do you need to call tcpListener.Stop() ? This thread runs throughout the life of the application, and if I need to call it, where would I do it? The listener is local to this thread. Instead of having a while (true) , will I have a while (appRunning) and set appRunning to false in the FormClosing event? Then, after the while loop, I could call tcpListener.Stop() .
However, it is even necessary to call tcpListener.Stop() because the application is already closed at this point, and since I use Tasks, does the process also end?
multithreading c #
John Smith Sep 19 '11 at 19:24 2011-09-19 19:24
source share