This is my Program class:
static class Program
{
private class MyAppContext : ApplicationContext
{
public MyAppContext()
{
//Exit delegate
Application.ApplicationExit += new EventHandler(this.OnApplicationExit);
//Show the main form
MainForm main = new MainForm();
main.Show();
}
private void OnApplicationExit(object sender, EventArgs e)
{
//Cleanup code...
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyAppContext());
}
}
When I'm running the app in debug mode and I close it, the main form closes, but the app is still running and I have to click on Stop Debugging
to terminate it completely.
In the main form, all I do is:
protected override void OnFormClosed(FormClosedEventArgs e)
{
base.OnFormClosed(e);
Application.Exit();
}
What am I doing wrong?