/// <summary> /// use struct, no break /// </summary> /// <typeparam name="T"></typeparam> /// <param name="iterator"></param> /// <param name="action"></param> public static void forEach <T>(this IEnumerable <T> iterator, Action <T> action) { if (iterator.count() > JConst.LOOP_WARNING_COUNT) { Trace.TraceInformation($"OVER LOOP WARNING COUNT ({JConst.LOOP_WARNING_COUNT})"); } var index = 0; foreach (var item in iterator) { action(item); if (index % JConst.LOOP_LIMIT == 0) { JConst.setInterval(JConst.SLEEP_INTERVAL); } index++; } }
public static void forEach <T>(this IEnumerable <T> iterator, Func <T, int, bool> func) { if (iterator.count() > JConst.LOOP_WARNING_COUNT) { Trace.TraceInformation($"OVER LOOP WARNING COUNT ({JConst.LOOP_WARNING_COUNT})"); } var index = 0; foreach (var item in iterator) { var isBreak = !func(item, index); if (isBreak) { break; } if (index % JConst.LOOP_LIMIT == 0) { JConst.setInterval(JConst.SLEEP_INTERVAL); } index++; } }