Collection was modified; enumeration operation may not execute

  • Thread starter Thread starter Jeff0803
  • Start date Start date
J

Jeff0803

Guest
"System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute." error occur from following code.


public void CheckGarbageReminderScheduleItem(List<Appointment> appointmentlist, List<ReminderSchedule> reminderscheduelist)
{
bool exist;
foreach (ReminderSchedule reminderschedule in reminderscheduelist)
{
exist = false;
foreach (Appointment appointment in appointmentlist)
{
if (reminderschedule.Appointment.ApptNo == appointment.ApptNo)
{
exist = true;
break;
}

}
if (exist == false)
{
DeleteReminderScheduleDB(reminderschedule.Appointment.ApptNo);
reminderschedule.Stop();
reminderscheduelist.Remove(reminderschedule);
}
}

}



ReminderSchedule class is inherited from System.Windows.Forms.Timers and remindschedulelist is List<ReminderSchedule>.

And this method is called like this.

CDMrCommon.Instance.CheckGarbageReminderScheduleItem(appointmentlist, reminderschedulelist);

CDMrCommon.Instance is a static method like following.

public static CDMrCommon Instance
{
get
{
if (m_CDMrCommon != null)
{
return m_CDMrCommon;
}
else
{
m_CDMrCommon = new CDMrCommon();
return m_CDMrCommon;
}
}
}
Can anybody give me some advice about this error?

Continue reading...
 
Back
Top