Code won't exit foreach block
Posted
by Matt
on Stack Overflow
See other posts from Stack Overflow
or by Matt
Published on 2010-05-28T03:00:57Z
Indexed on
2010/05/28
3:11 UTC
Read the original article
Hit count: 216
I've got the following C# code segment that takes a list, finds objects that are ready to update, then shoves them into a temp list, deletes from the main list, and then goes on its merry way. My issue is that the foreach block, which cycles through my main list, won't exit.
TempLog.Clear(); //Ensure TempLog is empty
foreach (CLogger ready in PlayerLog)
{
if (ready.UpdateReady == true) // Record is ready to be updated in database
{
TempLog.Add(ready); // Add record to templog
PlayerLog.Remove(ready); // Remove from playerlog
}
}
<---- Never reaches this point
if (TempLog.Count > 0) // Just check that templog isn't empty
{
new Thread(Update).Start(); // Run update code
}
I've put heaps of debugging in, and I can watch PlayerLog start at 1, TempLog at 0, then it enters the foreach loop, picks up that the record UpdateReady flag is on, TempLog goes to 1, PlayerLog goes to 0, then it just stops.. No errors, just stops..
Thanks for the help :)
© Stack Overflow or respective owner