fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public void DoReport(int prog)
  6. {
  7. Console.WriteLine("Progress {0}", prog);
  8. }
  9.  
  10. public void DoCount(int t, IProgress<int> iprog = null)
  11. {
  12. Console.WriteLine("Doing loops to {0}", t);
  13.  
  14. for (int j = 0; j < t; j++)
  15. {
  16. if (iprog != null)
  17. iprog.Report(j);
  18. Thread.Sleep(1000);
  19. }
  20. }
  21.  
  22. public async void SomeTaskAsync(int t)
  23. {
  24. Progress<int> iprog = new Progress<int>(pr => { DoReport(pr); });
  25.  
  26. // ((IProgress<int>)iprog).Report(72);
  27. await Task.Run(() => { DoCount(t, iprog); });
  28. // ((IProgress<int>)iprog).Report(83);
  29. Console.WriteLine("Finished Async.");
  30. }
  31.  
  32. public static void Main()
  33. {
  34. Test test = new Test();
  35.  
  36. test.SomeTaskAsync(7);
  37. Console.WriteLine("Finished.");
  38.  
  39. Thread.Sleep(8000);
  40. }
  41. }
  42.  
Success #stdin #stdout 0.07s 30128KB
stdin
Standard input is empty
stdout
Doing loops to 7
Finished.
Progress 0
Progress 1
Progress 2
Progress 3
Progress 4
Progress 5
Progress 6
Finished Async.