Handling Application Events: On Application Exit
using System;
using System.Threading;
using System.Reflection;
using System.Windows.Forms;
public class HelloWorldForm : Form
{
public HelloWorldForm()
{
Text = "Hello, WindowsForms!";
}
}
public class ApplicationEventHandlerClass
{
public void OnApplicationExit(object sender, EventArgs e)
{
try
{
Console.WriteLine("The application is shutting down.");
}
catch(NotSupportedException)
{
}
}
}
public class MainClass
{
public static void Main()
{
HelloWorldForm FormObject = new HelloWorldForm();
ApplicationEventHandlerClass AppEvents = new ApplicationEventHandlerClass();
Application.ApplicationExit += new EventHandler(AppEvents.OnApplicationExit);
Application.Run(FormObject);
}
}
Related examples in the same category