Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. List<<List<string>> batches = splitListOfUrlStringsIntoBatches(urls, 50); // where 50 is the batch size
  2.  
  3. foreach (var batchList in listOfBatchLists)
  4. {
  5. var insertForBatch = RunBatch(batchList);
  6. allInsertAmounts.Add(insertForBatch);
  7. }
  8.  
  9. private int RunBatch(IEnumerable<string> batch)
  10. {
  11. var allWriteNum = 0;
  12. // this will run on one bound logical thread i think
  13. Parallel.ForEach(batch, (batchItem) => {
  14. var res = Client.GetAsync(batchItem.Item1).GetAwaiter().GetResult();
  15. var responseBody = res.Content.ReadAsStringAsync().GetAwaiter().GetResult();
  16. var strongType = JsonConvert.DeserializeObject<StrongType>(responseBody);
  17.  
  18. dbContext.add(strongType);
  19. allWriteNum++
  20. });
  21. return allWriteNum;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement