I'm writing a Windows Forms Application in C# that uses only one form. When I want to exit and close the application, I add the code
private void Defeat()
{
MessageBox.Show("Goodbye");
this.Close();
}
to the class Form1 : Form
, which is the form class that was automatically created by Visual Studio. But when this code runs, I get the following message:
An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
Additional information: A generic error occurred in GDI+.
A picture of the message:
What is the problem?
How should I exit my application?