[Mono-bugs] [Bug 349073] New: Application.Exit does not trigger FormClosing event

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Dec 16 03:42:23 EST 2007


https://bugzilla.novell.com/show_bug.cgi?id=349073


           Summary: Application.Exit does not trigger FormClosing event
           Product: Mono: Class Libraries
           Version: 1.2.5
          Platform: i686
        OS/Version: Linux
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at ximian.com
        ReportedBy: ai2097 at users.sourceforge.net
         QAContact: mono-bugs at ximian.com
          Found By: Community of Practice


When calling Application.Exit() in a WinForms based application, the
FormClosing event is not fired on active forms.

Steps to reproduce:

1. Compile the following (gmcs -target:winexe -r:System.Windows.Forms
<filename>):

using System;
using System.Windows.Forms;

namespace Bug {
    public class Form1 : Form
    {   
        public Form1()
        {   
            this.FormClosing += ClosingHandler;
            Button quit = new Button();
            quit.Text = "Exit";
            quit.Click += delegate(Object sender, EventArgs e)
                { Application.Exit(); };
            this.Controls.Add(quit);
        }

        public void ClosingHandler(Object sender, FormClosingEventArgs e)
        {   
            string message = "Are you sure?";
            string caption = "Confirm exit";
            MessageBoxButtons type = MessageBoxButtons.YesNo;
            MessageBoxIcon icon = MessageBoxIcon.Exclamation;
            DialogResult result = MessageBox.Show(message, caption, type,
icon);
            if(DialogResult.No == result)
            {   
                e.Cancel = true;
            }
        }
    }

    public class Bug
    {   
        public static void Main()
        {   
            Application.Run(new Form1());
        }
    }
}

2. Run the application via mono


Expected:

  Closing the window via the "Exit" button should trigger the dialog, and
answering "no" to the dialog should prevent the application from exiting.
Identical behavior should be observed if the window is closed via the window
manager.


Actual:

  Closing the window via the "Exit" button causes the application to exit
immediately. The expected behavior does occur when the window is closed via the
window manager.


Other notes:

  Because the FormClosing event is not fired when Application.Exit is called,
no opportunity is given to prevent the application from exiting. Likewise,
clean up code that depends on this behavior to save state will not be run if
the application exits in this manner, which is why this bug is being filed with
a "major" priority. The expected behavior is implied by the presence of the
CloseReason.ApplicationExitCall enumeration value, and can be confirmed on the
Microsoft implementation of .NET 2.0.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list