A
Anders Both
My client-server system, is begining (when more client are connected)
sometimes to throw an exception like this:
Collection was modified; enumeration operation may not execute.
foreach (tcClient per in tcClientList) <-- Exception throw by this line.
{
if (tcClient!=tcClientNow) tcClient.flush();
}
Does someone have a good advice about how to handle this situation. I know
that I can lock and use volatile and stuff. But the performance of the
system is wery important, and I feel that videly use of locking and
volatile, can cause slover performance.
1. How can I lock the enumeration so that other thread cannot alter or add
element to tcClientList, while enumerating.
2. How can I just ignore the exception completly.
Best Regards
Anders Both, Denmark.
sometimes to throw an exception like this:
Collection was modified; enumeration operation may not execute.
foreach (tcClient per in tcClientList) <-- Exception throw by this line.
{
if (tcClient!=tcClientNow) tcClient.flush();
}
Does someone have a good advice about how to handle this situation. I know
that I can lock and use volatile and stuff. But the performance of the
system is wery important, and I feel that videly use of locking and
volatile, can cause slover performance.
1. How can I lock the enumeration so that other thread cannot alter or add
element to tcClientList, while enumerating.
2. How can I just ignore the exception completly.
Best Regards
Anders Both, Denmark.