none
clean up when program closes RRS feed

  • Question

  • How do I run cleanup code when the program is closed by clicking the X icon at the top right corner?
    Thursday, October 18, 2012 4:19 PM

Answers

  • Use FormClosed or FormClosing event handlers.

    Please mark this post as answer if it solved your problem. Happy Programming!

    • Proposed as answer by sambeet Thursday, October 18, 2012 4:48 PM
    • Marked as answer by Mike FengModerator Wednesday, October 24, 2012 12:16 PM
    Thursday, October 18, 2012 4:20 PM
  • Which cleanup in particular? anyway Adavesh suggestion should work, but if you really want to clean on the application exit, use the ApplicationExit event, in the Program.cs:

            [STAThread]
            static void Main()
            {
                Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
    
               Application.EnableVisualStyles();
               Application.SetCompatibleTextRenderingDefault(false);
    
               Application.Run(new MonitorForm());
            }
    
            static void Application_ApplicationExit(object sender, EventArgs e)
            {
                //Cleanup
            }
    
    // more...


    -


    Thursday, October 18, 2012 6:23 PM

All replies

  • Use FormClosed or FormClosing event handlers.

    Please mark this post as answer if it solved your problem. Happy Programming!

    • Proposed as answer by sambeet Thursday, October 18, 2012 4:48 PM
    • Marked as answer by Mike FengModerator Wednesday, October 24, 2012 12:16 PM
    Thursday, October 18, 2012 4:20 PM
  • Which cleanup in particular? anyway Adavesh suggestion should work, but if you really want to clean on the application exit, use the ApplicationExit event, in the Program.cs:

            [STAThread]
            static void Main()
            {
                Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
    
               Application.EnableVisualStyles();
               Application.SetCompatibleTextRenderingDefault(false);
    
               Application.Run(new MonitorForm());
            }
    
            static void Application_ApplicationExit(object sender, EventArgs e)
            {
                //Cleanup
            }
    
    // more...


    -


    Thursday, October 18, 2012 6:23 PM