When executing the following function, I get this error message:
Collection was modified; enumeration operation may not execute.
The only thing that can modify lstClients is when I add one in it and I'm
sure that my listener isn't accepting another connection. As you can see,
I even locked it!!! What is wrong?
private void ReceiveMessage()
{
byte[] Packet = new byte[PACKET_SIZE];
string sValue;
int nSize;
while (Started)
{
lock (lstClients)
{
foreach (TcpClient Client in lstClients)
{
NetworkStream NetStream = Client.GetStream();
nSize = NetStream.Read(Packet, 0, PACKET_SIZE);
sValue = Encoding.ASCII.GetString(Packet, 0, nSize);
System.Windows.Forms.MessageBox.Show(sValue);
}
}
}
}