Skip to content

Instantly share code, notes, and snippets.

View rhinocerous's full-sized avatar

Aaron Gibson rhinocerous

  • Inland Empire, CA
  • 19:24 (UTC -07:00)
View GitHub Profile
@ctigeek
ctigeek / ParallelTaskRunnerExtension.cs
Created July 1, 2014 01:36
ParallelTaskRunnerExtension - Running tasks in parallel, but limiting the concurrency.
public static class ParallelTaskRunnerExtension
{
public static void RunTasks(this IEnumerable<Task> tasks, int maxConcurrency, Action<Task> taskComplete = null)
{
if (maxConcurrency <= 0) throw new ArgumentException("maxConcurrency must be more than 0.");
int taskCount = 0;
int nextIndex = 0;
var currentTasks = new Task[maxConcurrency];
foreach (var task in tasks)