Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<<List<string>> batches = splitListOfUrlStringsIntoBatches(urls, 50); // where 50 is the batch size
- foreach (var batchList in listOfBatchLists)
- {
- var insertForBatch = RunBatch(batchList);
- allInsertAmounts.Add(insertForBatch);
- }
- private int RunBatch(IEnumerable<string> batch)
- {
- var allWriteNum = 0;
- // this will run on one bound logical thread i think
- Parallel.ForEach(batch, (batchItem) => {
- var res = Client.GetAsync(batchItem.Item1).GetAwaiter().GetResult();
- var responseBody = res.Content.ReadAsStringAsync().GetAwaiter().GetResult();
- var strongType = JsonConvert.DeserializeObject<StrongType>(responseBody);
- dbContext.add(strongType);
- allWriteNum++
- });
- return allWriteNum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement