Note that there are some explanatory texts on larger screens.

plurals
  1. POExiting a program properly
    primarykey
    data
    text
    <p>I realize after i published my program , that it didnt exit properly as the process still exist in task manager.</p> <p>I've look into <a href="https://stackoverflow.com/questions/2414244/how-do-i-properly-close-a-winforms-application-in-c">How do I properly close a winforms application in C#?</a> and i found out that my <code>Application.Run(new MainForm());</code> is my login form.</p> <p>So my program runs like this.</p> <p>After login form , it will lead to either <code>AdminForm</code> or <code>UserForm</code>. </p> <p>So how do i do the exit program properly?</p> <h2>update</h2> <pre><code>//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.. } </code></pre> <p>Update 2 : I am currently editing this with Visual Studio 2012.</p> <p>My program starts with this form <img src="https://i.imgur.com/MfIhyOz.png" alt="SMECS"></p> <p>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. <img src="https://i.imgur.com/ZkiVhqw.png" alt="ASmecs"></p> <p>i just need to know how do i exit my program properly when i am in either <code>AdminForm</code> or <code>UserForm</code>..</p> <p>Update 3 :</p> <p>Login Form Code :</p> <pre><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)) &amp;&amp; !(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) &amp;&amp; this.CompareStrings(dr["SCSPass"].ToString(), txtPass.Text) &amp;&amp; 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) &amp;&amp; this.CompareStrings(dr["SCSPass"].ToString(), txtPass.Text) &amp;&amp; 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(); } </code></pre> <p>this is code from Program.cs(which is the one created by Visual Studio)</p> <pre><code>static class Program { /// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt; [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Login()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload