private async void ExecuteAsync_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();

            try
            {
                var results = await DemoMethods.RunDownloadAsync(progress, cts.Token);

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

            watch.Stop();

            var elapsedMs = watch.ElapsedMilliseconds;

            resultsWindow.Text += $"Total execution time was: {elapsedMs}{Environment.NewLine}";
        }
Ejemplo n.º 2
0
        private async void Button_Async_Click(object sender, RoutedEventArgs e)
        {
            asyncBtn.IsEnabled = false;
            var sw = new Stopwatch();

            sw.Start();
            var result = await DemoMethods.RunDownloadAsync();

            sw.Stop();
            PrintResults(result);
            output.Text       += $"Total time: " + sw.Elapsed;
            asyncBtn.IsEnabled = true;
        }
Ejemplo n.º 3
0
        private void executeSync_Click(object sender, RoutedEventArgs e)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            //var results = DemoMethods.RunDownloadSync();
            var results = DemoMethods.RunDownloadParallelSync();

            PrintResults(results);

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

            resultsWindow.Text += $"Total execution time: {elaspedMs}";
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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.º 6
0
        private async void executeAsync_Click(object sender, RoutedEventArgs e)
        {
            var progress = new Progress <ProgressReportModel>();

            progress.ProgressChanged += ReportProgress;

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

            try
            {
                var results = await DemoMethods.RunDownloadAsync(progress, cts.Token);

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

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

            resultsWindow.Text += $"Total execution time: {elaspedMs}";
        }
Ejemplo n.º 7
0
 private async Task ExecuteLongProcessAsync()
 {
     IProgress <ProgressReportModel> progress = new Progress <ProgressReportModel>();
     await DemoMethods.RunDownloadAsync(progress, _cts.Token);
 }