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}";
        }
예제 #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;
        }
예제 #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}";
        }
예제 #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;
        }
예제 #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}";
        }
예제 #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}";
        }
예제 #7
0
 private async Task ExecuteLongProcessAsync()
 {
     IProgress <ProgressReportModel> progress = new Progress <ProgressReportModel>();
     await DemoMethods.RunDownloadAsync(progress, _cts.Token);
 }