J
John Hatpin
I'm pretty new to C#, but I thought I understood the lock() function.
It seems I don't. While debugging, this code:
lock(TList)
{
foreach(UUID tID in TList)
{
Client.Assets.RequestImage(tID, UpdateT) ;
}
}
gives a runtime error with the "in" in "foreach" highlighted, and the
following message: "System.InvalidOperationException: Collection was
modified; enumeration operation may not execute."
Presumably, TList is changing in another thread while that loop is
running - I thought the lock() would prevent that from happening.
Note that RequestImage is a third-party library function, and knows
nothing of the local list TList. UpdateT is a callback event.
I'm using SharpDevelop on WinXP, everything up-to-date.
What's happening here?
It seems I don't. While debugging, this code:
lock(TList)
{
foreach(UUID tID in TList)
{
Client.Assets.RequestImage(tID, UpdateT) ;
}
}
gives a runtime error with the "in" in "foreach" highlighted, and the
following message: "System.InvalidOperationException: Collection was
modified; enumeration operation may not execute."
Presumably, TList is changing in another thread while that loop is
running - I thought the lock() would prevent that from happening.
Note that RequestImage is a third-party library function, and knows
nothing of the local list TList. UpdateT is a callback event.
I'm using SharpDevelop on WinXP, everything up-to-date.
What's happening here?