Hi,
I have written a windows application and when I try to exit the program with the following code
private void KYRPlusRadForm_FormClosing(...)
{
var res1 = MessageBox.Show(this, "Are yor sure?", "Exit",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (res1 == DialogResult.No)
{
e.Cancel = true;
}
else
{
this.Dispose();
}
}
private void KYRPlusRadForm_FormClosed(object sender,
FormClosedEventArgs e)
{
Application.Exit();
}
the form is closed, but it is still running in the program list via Task Manager.
How do you close and exit a program perminantly in C#?
Loading
Sam HobbsPosted Oct 11, 2011, 1:19 PM
You should call Close() to exit the application. That will work if there is just one form. If there is another form then you probably can close that form at the same time. Closing all forms will cause the message loop to stop and then the program will stop. Calling Application.Exit() might not give the form(s) an opportunity to do whatever they need to do when they are closed normally.
VulpesPosted Oct 11, 2011, 11:57 AM
Jaganathan BantheswaranPosted Oct 11, 2011, 8:27 AM
Use Environment.Exit(0) in Closed event.