public void Load(string filename) { Action<IEnumerable<Page>> saveAction = Save; var file = new WikiFileParser(filename); var workers = file .GetPages() .Chunk(800) .Select(x => saveAction.BeginInvoke(x, null, null)) .Aggregate(new Queue<IAsyncResult>(), (queue, item) => { queue.Enqueue(item); if (queue.Count > 8) queue.Dequeue().AsyncWaitHandle.WaitOne(); return queue; }); //Wait for the last bit to finish workers.All(x => x.AsyncWaitHandle.WaitOne()); }
public void Load(string filename) { Action <IEnumerable <Page> > saveAction = Save; var file = new WikiFileParser(filename); var workers = file .GetPages() .Chunk(800) .Select(x => saveAction.BeginInvoke(x, null, null)) .Aggregate(new Queue <IAsyncResult>(), (queue, item) => { queue.Enqueue(item); if (queue.Count > 8) { queue.Dequeue().AsyncWaitHandle.WaitOne(); } return(queue); }); //Wait for the last bit to finish workers.All(x => x.AsyncWaitHandle.WaitOne()); }