Пример #1
0
        private async void executeAsync_Click(object sender, RoutedEventArgs e)
        {
            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);
            }
            // cancelOperation_Click event handler creates a cancel on CancellationTokenSource
            // In the try block RunDownloadAsync is called. Inside that there is
            // cancellationToken.ThrowIfCancellationRequested(); which throws OperationCanceledException
            catch (OperationCanceledException)
            {
                resultsWindow.Text += $"The async download was cancelled. { Environment.NewLine }";
            }

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

            resultsWindow.Text += $"Total execution time: { elapsedMs }";
        }
        private void ExecuteSync_Click(object sender, RoutedEventArgs e)
        {

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

            DemoMethods.RunDownloadSync();

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

            resultsWindow.Text += $"Total execution time: { elapsedMs }";
        }
Пример #3
0
        private void executeSync_Click(object sender, EventArgs e)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

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

            PrintResults(results);

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

            resultsWindow.Text += $"Total execution time: { elapedMs }";
        }
        private async void ExecuteParallelAsync_Click(object sender, RoutedEventArgs e)
        {
            if (cancellationTokenSource.IsCancellationRequested)
                cancellationTokenSource = new CancellationTokenSource();

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

            await DemoMethods.RunDownloadParallelAsync();

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

            resultsWindow.Text += $"PARALLEL Total execution time: { elapsedMs }";
        }
Пример #5
0
        private async void ExecuteParallelAsync_Click(object sender, RoutedEventArgs e)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();
            Progress <ProgressReportModel> progress = new Progress <ProgressReportModel>();

            progress.ProgressChanged += ReportProgress;
            var results = await DemoMethods.RunDownloadParallelAsync(progress);

            PrintResults(results);

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

            resultsWindow.Text += $"Total execution time: { elapsedMs }";
        }
        private async void executeAsync_Click(object sender, RoutedEventArgs e)
        {
            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: { elapsedMs }";
        }