Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. {
  2. // var cpuCores = 8;
  3. // var threads = cpuCores - 1;
  4. // var settingThreadOption = System.Threading.ThreadPool.SetMaxThreads(
  5. // threads, threads);
  6. // var stopWatch = System.Diagnostics.Stopwatch.StartNew();
  7.  
  8. var strings = new List<string>();
  9. var recordTimedList = new ConcurrentBag<string>();
  10.  
  11. using (var finished = new System.Threading.CountdownEvent(1))
  12. {
  13. foreach (var @string in strings)
  14. {
  15. finished.AddCount();
  16.  
  17. System.Threading.ThreadPool.QueueUserWorkItem((System.Threading.WaitCallback)(async (state) =>
  18. {
  19. try
  20. {
  21. await WriteAsync(@string);
  22. recordTimedList.Add(@string);
  23. }
  24. finally
  25. {
  26. finished.Signal();
  27. }
  28. }));
  29. }
  30.  
  31. finished.Signal();
  32. finished.Wait();
  33. }
  34.  
  35. // stopWatch.Stop();
  36. // System.Diagnostics.Debug.WriteLine(
  37. // $"Elapsed Time: {stopWatch.ElapsedMilliseconds} ms");
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement