Ejemplo n.º 1
0
        private async void executeParalleAsync_Click(object sender, RoutedEventArgs e)
        {
            var progress = new Progress <ProgressReportModel>();

            progress.ProgressChanged += ReportProgress;

            var watch = System.Diagnostics.Stopwatch.StartNew();

            var results = await DemoMethods.RunDownloadParallelAsyncV2(progress);

            PrintResults(results);

            watch.Stop();
            var elaspedMs = watch.ElapsedMilliseconds;

            resultsWindow.Text += $"Total execution time: {elaspedMs}";
        }
Ejemplo n.º 2
0
        private async void Button_Async_V2_Progress_Click(object sender, RoutedEventArgs routedEventArgs)
        {
            asyncBtnAndProgress.IsEnabled = false;
            Progress <ProgressReportModel> progress = new Progress <ProgressReportModel>();

            progress.ProgressChanged += UpdateDefaultStyle;
            var sw = new Stopwatch();

            sw.Start();
            var result = DemoMethods.RunDownloadParallelAsyncV2(progress);

            sw.Stop();
            output.Text += $"Total time: " + sw.Elapsed;


            asyncBtnAndProgress.IsEnabled = true;
        }
        private async void ExecuteParallelAsync_Click(object sender, RoutedEventArgs e)
        {
            resultsWindow.Text = "";
            cts.Dispose();                       // Clean up old token source....
            cts = new CancellationTokenSource(); // "Reset" the cancellation token source..
            Progress <ProgressReportModel> progress = new Progress <ProgressReportModel>();

            progress.ProgressChanged += ReportProgress;

            var watch = System.Diagnostics.Stopwatch.StartNew();

            var results = await DemoMethods.RunDownloadParallelAsyncV2(progress, cts.Token);

            PrintResults(results);
            resultsWindow.Text += $"The async download was cancelled.{Environment.NewLine}";
            watch.Stop();

            var elapsedMs = watch.ElapsedMilliseconds;

            resultsWindow.Text += $"Total execution time was: {elapsedMs}{Environment.NewLine}";
        }