title: Using DialogResult Correctly
body: <p>In an answer to a recent question I had (<a href="https://stackoverflow.com/questions/16808268/backgroundworker-completes-before-dowork">Here</a>), Hans Passant stated that I should set the <code>DialogResult</code> to close my forms instead of <code>form.Close()</code> although I cannot seem to find out why?</p>
  
  <p>If I've read correctly, the MSDN documentation states that doing this will just hide the form instead of correctly disposing it which I believed <code>.Close()</code> to do?</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.form.dialogresult.aspx" rel="noreferrer">Extract</a> from documentation.</p>
  
  <blockquote>
    <p>The Close method is not automatically called when the user clicks the Close button of a dialog box or sets the value of the DialogResult property. Instead, the form is hidden and can be shown again without creating a new instance of the dialog box. Because of this behavior, you must call the Dispose method of the form when the form is no longer needed by your application.</p>
  </blockquote>
  
  <p>On the other hand, Microsoft has created a <a href="http://support.microsoft.com/kb/816145" rel="noreferrer">support page</a> that says how to use DialogResult property and in the "Verify It Works" section of this it states that clicking so will Close the form.</p>
  
  <p>So my question is two fold, should I continue to use Close or DialogResult instead; and does dialog result close or hide a form. From the code I made below (a simple form with two buttons), it would seem that it is indeed hidden only as a breakpoint on <code>this.Close()</code> is hit..(with <code>this.Close()</code> commented, the form still disappears, just not sure whether hidden or not)</p>
  
  <pre><code>    public Form1()
      {
          InitializeComponent();
          button1.Click += (s, e) =&gt;
              {
                   //I edited my question to include using
                  using(Form1 form = new Form1())
                  {
                      form.ShowDialog();
                  }
  
              };
          button2.Click += (s, e) =&gt; 
              {
                  this.DialogResult = DialogResult.OK;
                  this.Close();
              };
      }
  </code></pre>