示例#1
0
        private void btnGo_Click_old(object sender, RoutedEventArgs e)
        {
            progressBar.IsIndeterminate = true;
            txtStatus.Text      = "Please Wait";
            btnGo.IsEnabled     = false;
            btnCancel.IsEnabled = true;
            var task = PrimesCalculator.GetAllPrimesAsync(0, 250000);

            var tcont = task.ContinueWith(_ =>
            {
                try
                {
                    var results = task.Result;

                    lstResults.ItemsSource      = results;
                    txtStatus.Text              = "Done";
                    progressBar.IsIndeterminate = false;
                    btnGo.IsEnabled             = true;
                    btnCancel.IsEnabled         = false;
                }
                catch (AggregateException ex)
                {
                }

                catch (InvalidOperationException ex)
                {
                }
                return("Hello");
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
示例#2
0
        private void btnGo_Click1(object sender, RoutedEventArgs e)
        {
            txtStatus.Text           = "Calculating...";
            btnGo.IsEnabled          = false;
            btnCancel.IsEnabled      = true;
            progress.IsIndeterminate = true;

            PrimesCalculator.GetAllPrimesAsync(2, 180000)
            .ContinueWith(task =>
            {
                var results              = task.Result;
                lstResults.ItemsSource   = results;
                txtStatus.Text           = "Completed";
                btnGo.IsEnabled          = true;
                btnCancel.IsEnabled      = false;
                progress.IsIndeterminate = false;
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
示例#3
0
        private async Task <int> _run()
        {
            Task <List <int> > task = null;

            try
            {
                Debug.WriteLine("A");   // now
                progressBar.IsIndeterminate = true;
                txtStatus.Text      = "Please Wait";
                btnGo.IsEnabled     = false;
                btnCancel.IsEnabled = true;

                task = PrimesCalculator.GetAllPrimesAsync(0, 250000);

                Debug.WriteLine("B");   // now
                var results = await task;
                Debug.WriteLine("C");   // later

                lstResults.ItemsSource = results;
                txtStatus.Text         = "Done";

                Debug.WriteLine("D");// later

                return(results.Count);
            }
            catch (Exception ex)
            {
                txtStatus.Foreground = Brushes.Red;
                txtStatus.Text       = ex.Message;
            }
            finally
            {
                progressBar.IsIndeterminate = false;
                btnGo.IsEnabled             = true;
                btnCancel.IsEnabled         = false;
            }

            return(0);
        }
示例#4
0
        private async Task <string> goAsync()
        {
            Debug.WriteLine("1");
            txtStatus.Text           = "Calculating...";
            btnGo.IsEnabled          = false;
            btnCancel.IsEnabled      = true;
            progress.IsIndeterminate = true;

            Debug.WriteLine("2");

            var results = await PrimesCalculator.GetAllPrimesAsync(2, 180000);

            Debug.WriteLine("3");

            lstResults.ItemsSource   = results;
            txtStatus.Text           = "Completed";
            btnGo.IsEnabled          = true;
            btnCancel.IsEnabled      = false;
            progress.IsIndeterminate = false;

            Debug.WriteLine("4");

            return("Hello");
        }