Handling Application Events: OnIdle, OnThreadException, OnThreadExit : Application Event « Development Class « C# / C Sharp






Handling Application Events: OnIdle, OnThreadException, OnThreadExit

 


using System;
using System.Threading;
using System.Reflection;
using System.Windows.Forms;

public class HelloWorldForm : Form {
    public HelloWorldForm() {
    }

    public static void OnApplicationExit(object sender, EventArgs e) {
        try {
            Console.WriteLine("shutting down.");
        } catch (NotSupportedException) {
        }
    }

    public static void OnIdle(object sender, EventArgs e) {
        Console.WriteLine("idle.");
    }

    public static void OnThreadException(object sender, ThreadExceptionEventArgs e) {
        Console.WriteLine("caught!");
    }

    public static void OnThreadExit(object sender, EventArgs e) {
        Console.WriteLine("thread is shutting down.");
    }

    public static void Main() {
        HelloWorldForm FormObject = new HelloWorldForm();

        Application.ApplicationExit += new EventHandler(OnApplicationExit);
        Application.Idle += new EventHandler(OnIdle);
        Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException);
        Application.ThreadExit += new EventHandler(OnThreadExit);
        Application.Run(FormObject);
    }
}

 








Related examples in the same category

1.Application.Run
2.Handling Application Events: On Application ExitHandling Application Events: On Application Exit
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