Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading.Tasks;
- namespace temp
- {
- class Program
- {
- static void Main()
- {
- MainAsync().Wait();
- }
- static async Task MainAsync()
- {
- Console.WriteLine("Starting to download");
- var progress = new Progress<MyScanProgress>();
- progress.ProgressChanged += progress_ProgressChanged;
- await DownloadContent(progress);
- }
- static void progress_ProgressChanged(object sender, MyScanProgress e)
- {
- Console.WriteLine(e.PercentDone + " %");
- }
- public static async Task DownloadContent(IProgress<MyScanProgress> progress)
- {
- await Task.Run(() =>
- {
- Console.WriteLine("Dowloading content ..");
- for (int i = 0; i < 10; i++)
- {
- System.Threading.Thread.Sleep(500);
- if (progress != null)
- progress.Report(new MyScanProgress() { PercentDone = i * 10 });
- }
- if (progress != null)
- progress.Report(new MyScanProgress() { PercentDone = 100 });
- return "Resulttttttttttt";
- }).ContinueWith((t) =>
- {
- Console.WriteLine(t.Result);
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement