public void InvokeAndWait <K, V>(IMap <K, V> items, IBackgroundWorkerParamDelegate <Entry <K, V> > itemHandler) { if (items.Count == 0) { return; } if (!IsMultiThreadingAllowed() || items.Count == 1) { foreach (Entry <K, V> item in items) { itemHandler(item); } return; } List <Entry <K, V> > itemsList = new List <Entry <K, V> >(items.Count); foreach (Entry <K, V> item in items) { itemsList.Add(item); } RunnableHandle <Entry <K, V> > runnableHandle = new RunnableHandle <Entry <K, V> >(itemHandler, itemsList, ThreadLocalCleanupController); Runnable parallelRunnable = new ParallelRunnable <Entry <K, V> >(runnableHandle, true); Runnable mainRunnable = new ParallelRunnable <Entry <K, V> >(runnableHandle, false); QueueAndWait(items.Count - 1, parallelRunnable, mainRunnable, runnableHandle); }
public void InvokeAndWait <V>(IList <V> items, IBackgroundWorkerParamDelegate <V> itemHandler) { if (items.Count == 0) { return; } if (!IsMultiThreadingAllowed() || items.Count == 1) { for (int a = items.Count; a-- > 0;) { V item = items[a]; itemHandler(item); } return; } RunnableHandle <V> runnableHandle = new RunnableHandle <V>(itemHandler, items, ThreadLocalCleanupController); Runnable parallelRunnable = new ParallelRunnable <V>(runnableHandle, true); Runnable mainRunnable = new ParallelRunnable <V>(runnableHandle, false); QueueAndWait(items.Count - 1, parallelRunnable, mainRunnable, runnableHandle); }
public ParallelRunnable(RunnableHandle <V> runnableHandle, bool buildThreadLocals) { this.runnableHandle = runnableHandle; this.buildThreadLocals = buildThreadLocals; }