我得到這個錯誤在這行system.invalidoperationexception集合被修改枚舉操作可能無法System.Collections.Generic.Dictionary
錯誤說:
system.invalidoperationexception集合被修改枚舉操作可能無法在System.Collections.Generic.Dictionary「2.ValueCollection.Enumerator.MoveNext執行<>
線,我有錯誤在
foreach (ISkill skill in client.Spells.Values)
當我試圖用for
更換foreach
我有三個錯誤
UPDATE:我的全碼
public static void SaveSpells(GameState client)
{
if (client.Fake) return;
if (client.TransferedPlayer) return;
if (((client.Entity != null) && (client.Spells != null)) && (client.Spells.Count != 0))
{
foreach (ISkill skill in client.Spells.Values)
{
DeadPool.Database.MySqlCommand command;
if (skill.Available)
{
// if (skill.PreviousLevel != skill.Level)
{
command = new DeadPool.Database.MySqlCommand(MySqlCommandType.UPDATE);
command.Update("skills").Set("LevelHu2", skill.LevelHu2).Set("LevelHu", (long)skill.Souls).Set("Level", (long)skill.Level).Set("PreviousLevel", (long)skill.Level).Set("PreviousLevel", (long)skill.PreviousLevel).Set("Experience", (long)skill.Experience).Where("EntityID", (long)client.Entity.UID).And("ID", (long)skill.ID).Execute();
}
}
else
{
skill.Available = true;
command = new DeadPool.Database.MySqlCommand(MySqlCommandType.INSERT);
command.Insert("skills").Set("LevelHu2", skill.LevelHu2).Set("LevelHu2", skill.LevelHu2).Insert("LevelHu", (long)skill.Souls).Insert("Level", (long)skill.Level).Insert("PreviousLevel", (long)skill.Level).Insert("Experience", (long)skill.Experience).Insert("EntityID", (long)client.Entity.UID).Insert("ID", (long)skill.ID).Execute();
}
}
}
}
迭代時,不要在'client.Spells'中添加或刪除。這也包括來自不同的線程。並且,記得先搜索.. – user2864740
你是什麼意思,我不明白你兄弟 –