79219899

Date: 2024-11-24 11:01:46
Score: 3
Natty:
Report link

I have the same problem in one of my apps and I solve it by a flag.

        private bool isClosingConfirmed = false;

        private void Main_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (!isClosingConfirmed)
        {
            if (MessageBox.Show("Are you sure you want to close the 
                 application?", "Exit Confirmation", 
                 MessageBoxButtons.YesNo, MessageBoxIcon.Question) == 
                 DialogResult.Yes)
            {
                isClosingConfirmed = true;  // Set flag to prevent re-entry
                Application.Exit();          // Close the application
            }
            else
            {
                e.Cancel = true;  // Prevent form from closing
            }
        }
    }
Reasons:
  • Blacklisted phrase (1): I have the same problem
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): I have the same problem
  • Low reputation (0.5):
Posted by: Daryush