Ejemplo n.º 1
0
        private async void Test2_Click(object sender, RoutedEventArgs e)
        {
            source = new CancellationTokenSource();
            CancellationToken token = source.Token;

            SourcePausa = new PauseTokenSource();
            PauseToken tokenpausa = SourcePausa.Token;

            Test1.IsEnabled     = false;
            Test2.IsEnabled     = false;
            Pausa.IsEnabled     = true;
            Continuar.IsEnabled = true;
            Cancelar.IsEnabled  = true;
            Texto.Text          = "Se esta ejecutando un proceso muy largo";
            Progreso.Visibility = Visibility.Visible;
            bool b = await Task.Run(() => ProcesoMuyLargo(tokenpausa), token);

            if (b)
            {
                Texto.Text = "Se termino de ejecutar un proceso muy largo normalmente";
            }
            else
            {
                Texto.Text = "Se termino de ejecutar un proceso muy largo cancelado";
            }
            Test1.IsEnabled     = true;
            Test2.IsEnabled     = true;
            Pausa.IsEnabled     = false;
            Continuar.IsEnabled = false;
            Cancelar.IsEnabled  = false;
            Progreso.Visibility = Visibility.Hidden;
        }
Ejemplo n.º 2
0
        private async Task <bool> ProcesoMuyLargo(PauseToken EstaPausado)
        {
            for (int i = 0; i < 10; i++)
            {
                await EstaPausado.WaitWhilePausedAsync();

                Thread.Sleep(1000);
                if (source.IsCancellationRequested)
                {
                    return(false);
                }
            }
            return(true);
        }