E
Eric
I'm looking at this page in the MSDN right here:
ms-help://MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemcollectionsarraylist
classsynchronizedtopic2.htm
(or online here:
http://msdn.microsoft.com/library/d...mcollectionsicollectionclasssyncroottopic.asp)
And I'm interested in locking an ArrayList during the entire enumeration, as
shown in the example code. My problem is that I'm STILL getting "Collection
was modified; enumeration operation may not execute" error messages from
InvalidOperationException during enumeration. I have no doubt that another
thread is removing items from the list as I read them, but this page in the
MSDN leads me to believe that I can prevent that from happening while I'm
still enumerating.
My ArrayList has a synchronized wrapper declared like this:
protected static ArrayList nodes = ArrayList.Synchronized(new ArrayList());
I am enumerating through the list with "foreach" which normally would be a
very bad idea, but as in the example code, I have enclosed the entire
operation in lock (nodes.SyncRoot) { } ... So what am I doing wrong?
Thanks so much in advance.
ms-help://MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemcollectionsarraylist
classsynchronizedtopic2.htm
(or online here:
http://msdn.microsoft.com/library/d...mcollectionsicollectionclasssyncroottopic.asp)
And I'm interested in locking an ArrayList during the entire enumeration, as
shown in the example code. My problem is that I'm STILL getting "Collection
was modified; enumeration operation may not execute" error messages from
InvalidOperationException during enumeration. I have no doubt that another
thread is removing items from the list as I read them, but this page in the
MSDN leads me to believe that I can prevent that from happening while I'm
still enumerating.
My ArrayList has a synchronized wrapper declared like this:
protected static ArrayList nodes = ArrayList.Synchronized(new ArrayList());
I am enumerating through the list with "foreach" which normally would be a
very bad idea, but as in the example code, I have enclosed the entire
operation in lock (nodes.SyncRoot) { } ... So what am I doing wrong?
Thanks so much in advance.