Search code examples
c#close-application

End Application in C #


As a sample below, I am using an If statement for my Application, where if you press Yes, the Application should close. I click Yes, and No, and the Application just continues regardless. Does anyone know why this might happen?

if (diff_ULNDOB.Any())
{
     DialogResult result1 = System.Windows.Forms.MessageBox.Show("Cannot proceed with Cross Year checks! Please see Workbook " + output + "." + " Do you wish to close the Application?", "Error",
     MessageBoxButtons.YesNo);

    if (result1 == DialogResult.Yes)
    {
       System.Windows.Forms.Application.Exit();           
    }

    Progress.Error = true;
    break;
}

Solution

  • Add Environment.Exit(0); when you want to close your application.