В момент вызова Application.Exit
форма все еще открыта (событие закрытия даже не завершило обработку). Вызов Exit вызывает закрытие форм. Поскольку форма еще не закрыта, она снова проходит путь Closing
и попадает в ваш обработчик событий.
Один из способов обойти это - запомнить решение в переменной экземпляра
private bool m_isExiting;
private void xGameForm_FormClosing(object sender, FormClosingEventArgs e)
{
if ( !m_isExiting ) {
//Yes or no message box to exit the application
DialogResult Response;
Response = MessageBox.Show("Are you sure you want to Exit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (Response == DialogResult.Yes) {
m_isExiting = true;
Application.Exit();
}
}
public void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}