title: How to exit a Windows Forms Application in C#
body: <p>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</p>
  <pre><code>private void Defeat()
  {
      MessageBox.Show(&quot;Goodbye&quot;);
      this.Close();
  }
  </code></pre>
  <p>to the class <code>Form1 : Form</code>, which is the form class that was automatically created by Visual Studio. But when this code runs, I get the following message:</p>
  <blockquote>
  <p>An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll</p>
  <p>Additional information: A generic error occurred in GDI+.</p>
  </blockquote>
  <p>A picture of the message:</p>
  <p><img src="https://i.stack.imgur.com/nBRpA.jpg" alt="Error message" /></p>
  <p>What is the problem?</p>
  <p>How should I exit my application?</p>