Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. using System;
  2. using System.Threading.Tasks;
  3.  
  4. namespace temp
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. MainAsync().Wait();
  11. }
  12.  
  13. static async Task MainAsync()
  14. {
  15. Console.WriteLine("Starting to download");
  16. var progress = new Progress<MyScanProgress>();
  17. progress.ProgressChanged += progress_ProgressChanged;
  18. await DownloadContent(progress);
  19. }
  20.  
  21. static void progress_ProgressChanged(object sender, MyScanProgress e)
  22. {
  23. Console.WriteLine(e.PercentDone + " %");
  24. }
  25.  
  26. public static async Task DownloadContent(IProgress<MyScanProgress> progress)
  27. {
  28.  
  29. await Task.Run(() =>
  30. {
  31. Console.WriteLine("Dowloading content ..");
  32.  
  33. for (int i = 0; i < 10; i++)
  34. {
  35. System.Threading.Thread.Sleep(500);
  36. if (progress != null)
  37. progress.Report(new MyScanProgress() { PercentDone = i * 10 });
  38. }
  39. if (progress != null)
  40. progress.Report(new MyScanProgress() { PercentDone = 100 });
  41. return "Resulttttttttttt";
  42. }).ContinueWith((t) =>
  43. {
  44.  
  45. Console.WriteLine(t.Result);
  46. });
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement