I realize after i published my program , that it didnt exit properly as the process still exist in task manager.

I've look into [How do I properly close a winforms application in C#?](https://stackoverflow.com/questions/2414244/how-do-i-properly-close-a-winforms-application-in-c) and i found out that my `Application.Run(new MainForm());` is my login form.

So my program runs like this.

After login form , it will lead to either `AdminForm` or `UserForm`. 

So how do i do the exit program properly?

update
------

```
//this doesnt work//
private void UserForm_FormClosing(object sender, FormClosingEventArgs e)
{
    Application.Exit();
}

//==============//
private void User_Load(object sender, EventArgs e)
{
    some code i have..
}

```

Update 2 :
I am currently editing this with Visual Studio 2012.

My program starts with this form
![SMECS](https://i.imgur.com/MfIhyOz.png)

and after logging in either as admin or a user , they will be forwarded to this form.
This is the admin form. The user form have the same template , but different naming and some buttons are disabled for the user.
![ASmecs](https://i.imgur.com/ZkiVhqw.png)

i just need to know how do i exit my program properly when i am in either `AdminForm` or `UserForm`..

Update 3 :

Login Form Code :

```
private void loginscs_Click(object sender, EventArgs e)
        {

            try
            {
                string userNameText = txtUser.Text;
                string passwordText = txtPass.Text;
                string isAdmin = "yes";
                string isNotAdmin = "no";
if (!(string.IsNullOrEmpty(txtUser.Text)) && !(string.IsNullOrEmpty(txtPass.Text)))
                {
                    SqlConnection SCScon = new SqlConnection();
                    SCScon.ConnectionString = "Data Source=PEWPEWDIEPIE\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True";
                    SqlCommand cmd = new SqlCommand("SELECT ISNULL(SCSID, '') AS SCSID, ISNULL(SCSPass,'') AS SCSPass, ISNULL(isAdmin,'') AS isAdmin FROM SCSID WHERE SCSID='" + txtUser.Text + "' and SCSPass='" + txtPass.Text + "'", SCScon);
                    SCScon.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        if (this.CompareStrings(dr["SCSID"].ToString(), txtUser.Text) &&
                            this.CompareStrings(dr["SCSPass"].ToString(), txtPass.Text) &&
                            this.CompareStrings(dr["isAdmin"].ToString(), isAdmin))
                        {
                            MessageBox.Show("Hello " + txtUser.Text, "Admin", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            var adminf = new Admin(txtUser.Text);
                            this.Hide();
                            adminf.ShowDialog();
                        }
                        else if (this.CompareStrings(dr["SCSID"].ToString(), txtUser.Text) &&
                            this.CompareStrings(dr["SCSPass"].ToString(), txtPass.Text) &&
                            this.CompareStrings(dr["isAdmin"].ToString(), isNotAdmin))
                        {
                            MessageBox.Show(string.Format("Welcome {0}", txtUser.Text));
                            var userf = new UserForm(txtUser.Text);
                            this.Hide();
                            userf.ShowDialog();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Wrong ID/Pass");
                    }
                    SCScon.Close();
                }

```

this is code from Program.cs(which is the one created by Visual Studio)

```
static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Login());
        }
    }

```