fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. // 並列でダウンロードする処理
  6. private async Task<List<string>> LoadSomeDataAsync(List<string> idList)
  7. {
  8. var tasks = new List<Task<string>>();
  9. foreach (var id in idList)
  10. {
  11. // A:ここで並列にダウンロードできているのか?
  12. tasks.Add(DownloadAsync(id));
  13. }
  14.  
  15. await Task.WhenAll(tasks);
  16. // B:Resultを使うとデッドロックすると聞いたけどawaitしていれば大丈夫?
  17. return tasks.Select(task => task.Result).ToList();
  18. }
  19.  
  20.  
  21. // 何かをダウンロードする処理
  22. private async Task<string> DownloadAsync(string id)
  23. {
  24. await Task.Delay(2000);
  25. return id;
  26. }
  27.  
  28. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(6,19): error CS0246: The type or namespace name `Task' could not be found. Are you missing `System.Threading.Tasks' using directive?
prog.cs(22,19): error CS0246: The type or namespace name `Task' could not be found. Are you missing `System.Threading.Tasks' using directive?
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty