I call this below func with class list having 3 to 4 list items, in foreach loop i compare the system time with a set time and if the time of system exceeds them i remove that particular list from PIR_ConditionList
by calling:
PIR_ConditionList.RemoveAll(element => element == Li);
but i get the error:
Collection was modified; enumeration operation may not execute. removing list item
I deduct it is an error in foreach as u cannot remove item when in loop. is there another way or a solution to this.
Task.Factory.StartNew(() =>
{
try
{
while (PIR_ConditionList.Count>0)
{
foreach (var Li in PIR_ConditionList)
{
if (Li.dateimePresent < Li.datetimePlusFour)
{
var dimLevel = Li.dimLevel;
AcquisitionLoop.Luminaires.EnqueueCommand(new SetDimLVLNEW(new SetBrightnessNEW(Li.lumId, dimLevel, Li.lumNumId, Li.clusterId)));
Li.dateimePresent = DateTime.Now;
Thread.Sleep(10000);
}
else
{
PIR_ConditionList.RemoveAll(element => element == Li);
}
}
}
}
catch (Exception ee)
{
fourMinTimer();
}
});