title: Avoiding `ObjectDisposedException` while calling `Invoke`
body: <p>I have 2 forms, one is <code>MainForm</code> and second is <code>DebugForm</code>. The MainForm has a button that sets up and shows the DebugForm like this, And passes a reference to an already opened SerialPort:</p>
  
  <pre><code>private DebugForm DebugForm; //Field
  private void menuToolsDebugger_Click(object sender, EventArgs e)
  {
      if (DebugForm != null)
      {
          DebugForm.BringToFront();
          return;
      }
  
      DebugForm = new DebugForm(Connection);
  
      DebugForm.Closed += delegate
      {
          WindowState = FormWindowState.Normal;
          DebugForm = null;
      };
  
      DebugForm.Show();
  }
  </code></pre>
  
  <p>In the DebugForm, I append a method to handle the <code>DataReceived</code> event of the serialport connection (in DebugForm's constructor):</p>
  
  <pre><code>public DebugForm(SerialPort connection)
  {
      InitializeComponent();
      Connection = connection;
      Connection.DataReceived += Connection_DataReceived;
  }
  </code></pre>
  
  <p>Then  in the <code>Connection_DataReceived</code> method, I update a TextBox in the DebugForm, that is using Invoke to do the update:</p>
  
  <pre><code>private void Connection_DataReceived(object sender, SerialDataReceivedEventArgs e)
  {           
      _buffer = Connection.ReadExisting();
      Invoke(new EventHandler(AddReceivedPacketToTextBox));
  }
  </code></pre>
  
  <p>But I have a problem. As soon as I close the DebugForm, it throws an <code>ObjectDisposedException</code> on the <code>Invoke(new EventHandler(AddReceivedPacketToTextBox));</code> Line.</p>
  
  <p>How can I fix this? Any tips/helps are welcome!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I found out if I remove the event in a button event click , and close the form in that button click, everything is fine and my debugform gets closed without any exception...how odd!</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      Connection.DataReceived -= Connection_DebugDataReceived;
      this.Close();
  }
  </code></pre>