Stop the application after displaying a login error

Asked

Viewed 40 times

2

In the code below, the desktop application has to log in to a system, but when the user/password is wrong, it gives me the error message, but after I give the OK it keeps running. I tried the environment.exit() and application.exit() but they didn’t work. Nothing happened. How would you stop the application and start again? Or go back to where you left off?

public void ConsultarSistemaRJ(string codPrograma)
        {

            log.GravarLog("Sistema RJ", "");

            r.Espera("SELECIONE A OP", 17, 16, 29 );

            r.PutString("6", 17, 38);
            r.PutString("29", 17, 41);
            r.EnviaEnter();
            r.PutString(matricula, 8, 58);
            r.PutString(senha, 9, 58);
            r.EnviaEnter();

            **if (r.txTela.Contains("CEFSNP"))
            {
                login = false;
                MessageBox.Show("Login inválido!");
                return;
            }
            if (login == false)
            {
                Environment.Exit(0);
            }**


            r.Espera("PAS SIPAS", 11, 27, 35);

            r.PutString("PAS", 4, 15);
            r.EnviaEnter();
            r.PutString("001", 5, 15);
            r.EnviaEnter();
  • 1

    see help: https://answall.com/questions/205483/login-em-c-com-base-data

  • 1

    the execution of Application.Exit() is not immediate, it just signals to the OS that the application will close and then closes (qq thing running after the line will run), if your form is the main application you can call Close() to close the form and the application will close

1 answer

0


I figured I’d just put one Return to stop the method (what was in this code above), but then the next method executed, which screwed everything, because the previous method had been interrupted. I created a variable bool so that it did not execute when it was false.

Browser other questions tagged

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