Hi,
I hv foll. code:
foreach(object obj in myChkedlistbox.CheckedItems)
{
Messagebox.show(obj.tostring());
}

It gives me the foll exception:
"The list that this enumerator is bound to has been modified. An enumerator
can only be used if the list does not change."

I dont see where am I changing contents of myChkedlistbox list. What is
more surprising, at the same time the foll. (similar) code just works fine.

for (int i=0; i< dynColumns.CheckedItems.Count;i++)
{
object itemChecked = dynColumns.CheckedItems[i];
MessageBox.Show(itemChecked.ToString());
}

One more confusing thing is that the exception doesnt come on each run.
Once in a while the exception pops up and then after that its v.consistent
to the point that I reduce my code to:
foreach(object obj in myChkedlistbox.CheckedItems)
{} //Yes empty loop.

& still throws the exception..whoa !!

However If I do a clean-rebuild it goes away and just works :-? until some
mysterios next time when it decides to revisit again.

Re: List enumeration exception under weird circumstances. by Richard

Richard
Fri Jan 07 03:32:55 CST 2005

Do you have another thread running processing the dynColumns.CheckedItems list?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,
I hv foll. code:
foreach(object obj in myChkedlistbox.CheckedItems)
{
Messagebox.show(obj.tostring());
}

It gives me the foll exception:
"The list that this enumerator is bound to has been modified. An enumerator
can only be used if the list does not change."

I dont see where am I changing contents of myChkedlistbox list. What is
more surprising, at the same time the foll. (similar) code just works fine.

for (int i=0; i< dynColumns.CheckedItems.Count;i++)
{
object itemChecked = dynColumns.CheckedItems[i];
MessageBox.Show(itemChecked.ToString());
}

One more confusing thing is that the exception doesnt come on each run.
Once in a while the exception pops up and then after that its v.consistent
to the point that I reduce my code to:
foreach(object obj in myChkedlistbox.CheckedItems)
{} //Yes empty loop.

& still throws the exception..whoa !!

However If I do a clean-rebuild it goes away and just works :-? until some
mysterios next time when it decides to revisit again.


Re: List enumeration exception under weird circumstances. by sk

sk
Wed Jan 19 00:55:01 CST 2005

Hi Richard,
Thanks for yr reply.
No, I do not have any other threads running the same. Its a simple one
form,one toolwindow(as a VSIP pkg), serial code.

Rgds,
-sk

"Richard Blewett [DevelopMentor]" wrote:

> Do you have another thread running processing the dynColumns.CheckedItems list?
>
> Regards
>
> Richard Blewett - DevelopMentor
> http://www.dotnetconsult.co.uk/weblog
> http://www.dotnetconsult.co.uk