Skip to content

Instantly share code, notes, and snippets.

@takekazuomi
Created April 22, 2011 08:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save takekazuomi/936277 to your computer and use it in GitHub Desktop.
main loop
try {
if (concurrency == 1) {
foreach (var es in EntityGenerator<EntityOne>.Shift(source, batchSize)) {
body(es, null, monitor);
}
} else {
ParallelOptions options = new ParallelOptions();
options.MaxDegreeOfParallelism = concurrency;
var result = Parallel.ForEach<IEnumerable<EntityOne>, ElapsedMonitor>(
EntityGenerator<EntityOne>.Shift(source, batchSize),
options,
() => new ElapsedMonitor(),
body,
(m) => {
lock (monitor) {
monitor.Merge(m);
}
});
}
} catch (Exception e) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment