//method for wrap around for loops, 0, 1, 2, 3, 4, ..., 0, 1, 2, 3 public static void For(int start, LoopConditional condition, LoopBody body, LoopConclusion conclusion) { var events = new List<ManualResetEvent>(); for (int i = start, j = 0; condition.Invoke(i); i++, j++) { var resetEvent = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem((arg) => { int value = (int)arg; body.Invoke(value); resetEvent.Set(); }, i); events.Add(resetEvent); conclusion.Invoke(ref i); }//end loop WaitHandle.WaitAll(events.ToArray()); }
//method for wrap around for loops, 0, 1, 2, 3, 4, ..., 0, 1, 2, 3 public static void For(int start, LoopConditional condition, LoopBody body, LoopConclusion conclusion) { var events = new List <ManualResetEvent>(); for (int i = start, j = 0; condition.Invoke(i); i++, j++) { var resetEvent = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem((arg) => { int value = (int)arg; body.Invoke(value); resetEvent.Set(); }, i); events.Add(resetEvent); conclusion.Invoke(ref i); }//end loop WaitHandle.WaitAll(events.ToArray()); } //end method