Execution console hangs while doing many readings in debug mode!

Asked

Viewed 160 times

0

In an attempt to debug the code for errors, I often need to enter the requested data, but it is not always possible to reach the end of the program because the execution of the debug via "F10" or "F11" (if you can tell the difference) lock making it impossible to read the next data.

I don’t know why this is happening, and I haven’t found anything about it either. If you can help me with that I’d be grateful.

Here’s a screenshot of the running problem:

Console Executando em Modo Debug

using System;

namespace SomaMedia
{
    class Program
    {
        static void Main()
        {
            string nome_candidato = " ";
            int qt_eleitores = 0, qt_brancos = 0, qt_indecisos = 0, qt_intencoes;
            int cont = 0, maior = 0, menor = 0;
            double percentual_intencoes = 0, percentual_indecisos = 0, percentual_brancos = 0;
            int? cod_candidato = null;

            while (cod_candidato != 0)
            {
                Console.Write("QUANTIDADE DE ELEITORES: ");
                qt_eleitores = int.Parse(Console.ReadLine());
                Console.WriteLine();

                Console.Write("CÓDIGO DO CANDIDATO: ");
                cod_candidato = int.Parse(Console.ReadLine());
                Console.WriteLine();

                if (cod_candidato == 0)
                {
                    break;
                }

                Console.Write("NOME DO CANDIDATO: ");
                nome_candidato = Console.ReadLine();
                Console.WriteLine();

                Console.Write("INTENÇÕES DE VOTO: ");
                qt_intencoes = int.Parse(Console.ReadLine());
                Console.WriteLine();

                Console.Write("VOTOS EM BRANCO: ");
                qt_brancos = int.Parse(Console.ReadLine());
                Console.WriteLine();

                Console.Write("VOTOS INDECISOS: ");
                qt_indecisos = int.Parse(Console.ReadLine());
                Console.WriteLine();

                if (cont == 0)
                {
                    maior = qt_intencoes;
                    menor = qt_intencoes;
                }

                if (qt_intencoes > maior)
                {
                    maior = qt_intencoes;
                }

                if (qt_intencoes < menor)
                {
                    menor = qt_intencoes;
                }

                percentual_intencoes = ((qt_intencoes / qt_eleitores) * 100);
                percentual_brancos = ((qt_brancos / qt_eleitores) * 100);
                percentual_indecisos = ((qt_indecisos / qt_eleitores) * 100);

                Console.WriteLine($"{percentual_intencoes}% - {nome_candidato}");


            }

            Console.WriteLine($"{percentual_brancos}% - VOTOS EM BRANCO");
            Console.WriteLine($"{percentual_indecisos}% - VOTOS INDECISOS");

        }
    }
}
  • Dear Ramon, could you post your code for us to analyze? Thank you. By your image I can see that the process is stopped at a breakpoint.

  • Ramon, that "via "F10" or "F11" (if you can tell the difference) hangs making it impossible to read the next data." was not clear to me, can explain better? About the F10 and F11, if it is in a method call (for example var x = ObterValor(); and use F11, Debugger will enter the "Get value" method if using F10, does not enter the method, just executes and goes to the next line.

  • Paulo, as requested, follows the code. But this happens with any code I try to debug.

  • Ricardo, next: There was more data to read, right? But after I type what was requested the console is not closed to continue the execution, forcing me to quit by pressing "x" and run the code again.. Sometimes it goes, sometimes it doesn’t. ?

  • @Ramonalmeida Do you press the key in Visual Studio or console? Did F5 as well?

  • @Maniero Worked right here! I was hoping that when I input, the screen would be closed as at the beginning so I could continue with debugging. But just click on Visual Studio and press the F10 that remains normal. Thanks!

Show 1 more comment

1 answer

1


Ramon what is occurring is not a problem, but a misunderstanding of running a program via Visual Studio Console.

From your image I can see yellow arrow, which indicates that your code is stopped at breakpoint waiting for you to continue debugging.

You said in the comments that you are bound to tighten the X to run the process again, but in fact what is happening is that the program is stopped running the debug waiting for its interaction.

To solve your "problem", go back to the code and continue running your program by pressing F5, F10 or F11.

Function of F5

Continue running the program until the end or until you find a next breakpoint in the algorithm flow.

Function of the F10

Runs line by line from the algorithm without entering methods that are along the flow. For example:

int numero = 0;

//Outros códigos que alteram o valor da variável numero

if (numero > 10)
{
    Calcular(numero);
}

If we press F10 when debugging is in the method Calcular(numero) all codes inside the function will be executed, but we will not see what is happening inside it.

Function of F11

Runs line by line algorithm, but in this case we enter methods that are along the flow. For example:

int numero = 0;

//Outros códigos que alteram o valor da variável numero

if (numero > 10)
{
    Calcular(numero);
}

If we press F11 when debugging is in the method Calcular(numero) we will pass within the definition of the method Calculate, being able to analyze what is happening in this interaction of the algorithm flow, analyzing value assignment, calls of other methods, executions of rules, etc.

  • His explanation as well as that of Maniero helped me.. It really was a misunderstanding on my part (I imagined it was that). Thanks for the help.

  • For nothing my dear, we are together!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.