I have a List and two threads that using the List.
The first thread is getting new connections, each new connection is added to the List.
The second thread looping over the List to handle the connections (using foreach).
The problem is that sometimes while the second thread is looping over the List, the List changes before the loop ends. I even tried creating a new copy of the list and looping over it. But it produces some other problems.
I don't want to create a new thread to handle each new connection, because I understood that too many threads can hurt performance. Is there any other way to handle the connections?