我真的无法深入了解这个错误,它可能是可见的,但需要一双额外的眼睛!
try
{
while (Program.Alive)
{
List<Session> ToDispose = new List<Session>();
List<Session> ToStop = new List<Session>();
lock (mSessions)
{
lock (mSessionsToStop)
{
foreach (uint SessionId in mSessionsToStop)
{
if (mSessions.ContainsKey(SessionId))
{
ToStop.Add(mSessions[SessionId]);
}
}
mSessionsToStop.Clear();
}
foreach (Session Session in mSessions.Values)
{
if (ToStop.Contains(Session))
{
continue;
}
if (Session.Stopped)
{
if (Session.TimeStopped > 15)
{
ToDispose.Add(Session);
}
continue;
}
}
}
if (ToStop.Count > 0)
{
using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
{
foreach (Session SessionStop in ToStop)
{
SessionStop.Stop(MySqlClient);
}
}
}
foreach (Session SessionDispose in ToDispose)
{
SessionDispose.Dispose();
lock (mSessions)
{
if (mSessions.ContainsKey(SessionDispose.Id))
{
mSessions.Remove(SessionDispose.Id);
}
}
}
Thread.Sleep(70);
}
}
catch (Exception e)
{
Output.WriteLine("[ExecuteMonitor.Error] " + e.Message, OutputLevel.CriticalError);
}
它在一个单独的线程中运行,我们总是收到有关 Collection 已修改的错误;枚举操作可能无法执行