fork download
  1. var urls = new ConcurrentQueue<string>(Directory.GetFiles(@"C:\Windows\System32"));
  2. var total = urls.Count;
  3. var tasks = new Task[20];
  4. var rand = new Random();
  5.  
  6. for (int i = 0; i < tasks.Length; i++)
  7. {
  8. tasks[i] = new Task(() =>
  9. {
  10. string url;
  11.  
  12. while (urls.TryDequeue(out url))
  13. {
  14. Console.WriteLine(url);
  15. Thread.Sleep(1000 + rand.Next(4000));
  16. }
  17. });
  18. }
  19.  
  20. var prog = Task.Factory.StartNew(() =>
  21. {
  22. foreach (var t in tasks)
  23. {
  24. t.Start();
  25. }
  26.  
  27. while (!Task.WaitAll(tasks, 1000))
  28. {
  29. Console.WriteLine(100 * urls.Count / total);
  30. }
  31. });
  32.  
  33. prog.Wait();
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty