Skip to content

Instantly share code, notes, and snippets.

@arman-hpp
Created January 13, 2018 17:47
Show Gist options
  • Save arman-hpp/7ba44364a64d9094027bdeb7ee0b3516 to your computer and use it in GitHub Desktop.
Save arman-hpp/7ba44364a64d9094027bdeb7ee0b3516 to your computer and use it in GitHub Desktop.
Parallel.ForEach Progress
SynchronizationContext ctx = SynchronizationContext.Current;
int count = 0;
Parallel.ForEach(collection, (item) =>
{
ComputeYourStuff(item);
Interlocked.Increment(ref count);
ctx.Post(d => { progressBar.Value = count; }, null);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment