Handling Application Events: On Application Exit : Application Event « Development Class « C# / C Sharp






Handling Application Events: On Application Exit

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

1.Application.Run
2.Handling Application Events: OnIdle, OnThreadException, OnThreadExit
3.Handling Application Events: On IdleHandling Application Events: On Idle
4.Handling Application Events: Thread ExceptionHandling Application Events: Thread Exception
5.Handling Application Events: On Thread ExitHandling Application Events: On Thread Exit
6.Installing a Message Filter
7.Removing an Installed Message Filter