Visual Studio C# 2015 does not debug

Asked

Viewed 110 times

1

Here’s what I’m trying to do:

  1. I compile the program by clicking start;
  2. The screen splash is displayed, the progress bar rotates and reaches 100% (closes the screen splash);
  3. Opens the screen of login, the identification is placed and everything happens correctly (the identification screen is closed);

  4. Open the screen home (main), and when closing the screen home for X (not yet put the other buttons) Visual Studio keeps running, the compilation does not stop until I press the stop button of Visual Studio.

What would you like to happen, when entering user and password, the screen login was closed and only the screen appeared home.

What am I doing wrong??

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace App.Sis_Igreja
{
    public partial class frm_inicial : Form
    {
        public frm_inicial()
        {
            InitializeComponent();
        }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        String usuario = tb_usuario.Text;
        String senha = tb_senha.Text;

        if (String.IsNullOrEmpty(usuario) || (String.IsNullOrEmpty(senha)))
        {
            MessageBox.Show("Por favor preencha todos os campos!!");
        }else
        {
            String config = "server=localhost; userid=root; pwd=root; database=sis_igreja";
            MySqlConnection conexao = new MySqlConnection(config);
            MySqlCommand Query = new MySqlCommand();
            Query.Connection = conexao;
            conexao.Open();
            Query.CommandText = "select usuario, senha from login where usuario = '" + usuario + "' and senha = '" + senha + "'";
            bool verifica = Query.ExecuteReader().HasRows;

        if (verifica == true)
        {
                String titulo = "Bem Vindo";
                String mensagem = "Usuário Logado com Sucesso";
                MessageBox.Show(titulo, mensagem);
                MessageBoxButtons botao = MessageBoxButtons.OK;
                //DialogResult resultado = ;
                if( botao == MessageBoxButtons.OK)
                {
                    this.Close();
                }
                frm_gerenciamento frm = new frm_gerenciamento();
                frm.Show();

        }
        else
        {
            MessageBox.Show("Nome do usuário ou senha incorreto!");
        }
        conexao.Close();
        }
    }
}
}

Program.Cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace App.Sis_Igreja
{
    static class Program
    {
        /// <summary>
        /// Ponto de entrada principal para o aplicativo.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new SplashScreen());
        }
    }
}

Follow the Splash form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace App.Sis_Igreja
{
    public partial class SplashScreen : Form
    {
        public SplashScreen()
        {
            InitializeComponent();
        }

        private void progressBar1_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lb_porcentagem.Text = pb_splash.Value + "%";

            if (pb_splash.Value < 100)
            {
                pb_splash.Value = pb_splash.Value + 2;
            }
            else
            {
                timer1.Enabled = false;
                frm_inicial frm = new frm_inicial();
                frm.Show();
                this.Visible = false;
                //comentario
            }
        }
    }
}
  • Start the project with CTRL+F5. Or go to Debug -> Start Without Debug

  • It worked, but there is some problem in you with debug in my case ?

  • No, that’s standard Visual Studio. When you run debugging, there are other "tied" processes to your program that monitor it, so it keeps running even when you close your screen.

  • puts the code of Program.Cs and frm_management

  • I’m not able to make other blocks to post what you asked for. have to help in this too ?

  • like other blocks ? editing the question ?

  • I think the best thing to do is to clone your project and get out taking away everything that does not influence the problem. Then you put all the code here.

  • @Rovannlinhalis yes, I’m not getting it

  • @Fabioaragdon’t click here: https://answall.com/posts/226047/edit. and to format the text, give 4 spaces before the code block, or put it between two high accents ``` to separate the blocks, just skip the line and write something without obeying this formatting

  • I tried and it didn’t work

  • @Fabioaragão the problem is that you start the application by Splashscreen, and if it continues like this, when users close the application, it will continue running on the machine, without being accessible.

  • see the answer, if you want more details, enter the code of the SplashScreen also... rs

Show 7 more comments

2 answers

3


The problem is that you start the application with Splashscreen, this causes the application to continue running after you close the other Forms, possibly after the login you are giving a Hide() in Splash.

If your main application form is the frm_gerenciamento he who must be in Application.Run(new frm_gerenciamento()); and not the SplashScreen.

To do this, something like this can be done:

No Program.Cs:

    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);


        FormLogin form = new FormLogin();
        if (form.ShowDialog() == DialogResult.OK)
        {
             Application.Run(new frm_gerenciamento());
        }
        else
            Application.Exit();
    }

No Formlogin:

   Load()
   {
      //Mostra sua splashScreen se quiser... 
   }

   btnLogin_click()
   {
      if([validar login])
      {
          this.DialogResult = DialogResult.OK;
      }
      else 
          //Login inválido

   }

   btnCancelar_click()
   {
       this.DialogResult = DialogResult.Cancel;
   }
  • 1

    +1 Good! Explained the reason for the problem, while I just focused on the solution.

  • @Rovann I couldn’t make the formLogin, I couldn’t fit it into my code. It might help ?

  • @Fabioaragão yes, show what you’ve done

  • I saw the splash code and, would not do it...rs the screen does nothing but delay the opening, rs only makes some sense if there is some propaganda in it, I think that is not the case. For now, leave without the splash and focus on login and main form.

1

You can start your application without specifying an instance of Form to the method Run, giving Show in the frm before the Run. Thus:

static class Program
{
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        var frm = new Form1();
        frm.Show();

        Application.Run();
    }
}

In doing so, you have to call Application.Exit() explicitly to terminate the application.

You can implement Forms to do this automatically when the open Forms count is zero (Application.OpenForms.Count == 0). For this you will need to implement the event OnFormClosed on all Forms. For example:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        var frm = new Form1();
        frm.Show();
        this.Close();
    }

    protected override void OnFormClosed(FormClosedEventArgs e)
    {
        base.OnFormClosed(e);
        if (Application.OpenForms.Count == 0)
            Application.Exit();
    }
}

Browser other questions tagged

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