You must exit the method (or call the Save() method you may have) after setting the
e.Cancel = true
. Now the application terminates not matter what, because
Environment.Exit(0);
always gets executed.
if (MessageBox.Show("Do you want to save changes to your text?", "My Application",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
e.Cancel = true;
return;
}
objS3Instance = null;
Environment.Exit(0);