Rules

Secret ingredients to quality software

Edit
Info

Do you provide a warning before the program exits?

Created on 27 Nov 2012 | Last updated by Rebecca Liu on 08 May 2013 06:53 AM (almost 8 years ago)

A product should not close without providing a warning. We use the following message box to warn the user before closing a program:

Figure: Good Example - Standard warning before a program exits

private void OnExit(object sender) 
             { 
                EventHandler handler = ExitRequest; 
                if (handler!= null ) 
                { 
                   handler(sender, EventArgs.Empty);
                   return;
                } 
                string closeTitle = string.Format("Exiting{0}", Application.ProductName);
                string closeMessage = string.Format("Are you sure you want to exit {0}", Application.ProductName);
                DialogResult result = MessageBox.Show(closeMessage,closeTitle, MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                { 
                   Application.Exit();
                } 
             }

We have an example of this in the SSW .NET Toolkit.


We open source. This page is on GitHub