Q:

Windows Form Desktop application Log out

On start of my Application Login Form comes up I have simply stored username and password and compared for validating user, if user is valid than MDIparent Form gets opened, Now I want to create logout for this Application. How I can do this?
When I searched I Found That I can do this on FormClosing Event or FormClosed Event but what code should be written in that and for which form, only Dispose(); is enough or something more? 
What if I want Login Form to get displayed back?
Showing MDI Form after Successful Login Like this 
private void login_Click(object sender, EventArgs e)
        {   
            //if password true then send true           
            bool value = namePasswordEntry(getHashedUserName, txtUserName.Text, getHashedPassword, txtPassword.Text);
            if (value ==true)
            {                
                MessageBox.Show("Thank you for activation!");
                this.Hide();
                Form2 pfrm = new Form2(txtUserName.Text);
                pfrm.ShowDialog();    
            }

            else
            {
                MessageBox.Show("Invalid LoginName or Password..");
            }       
        }

A:

Try the following codes in the form closing event
Application.Exit(); - Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.
System.Environment.Exit(1); - Terminates this process and gives the underlying operating system the specified exit code.
Application.Restart() - Shuts down the application and starts a new instance immediately.
Source : http://msdn.microsoft.com/

