title: invoke causes Cannot access a disposed object
body: <p>I have a <code>form</code> in load page i create a thread and delegate to show a position that every time is updated :</p>
  
  <pre><code>   private delegate void UpdateListBoxDelegate();
    private UpdateListBoxDelegate UpdateListBox = null;
  
  private void frmMain_Load(object sender, EventArgs e)
          {
               pictureBoxonlineTrain.Parent = pictureBoxMetroMap;
              UpdateListBox = new UpdateListBoxDelegate(this.UpdateStatus);
              // Initialise and start worker thread
              workerThread = new Thread(new ThreadStart(this.GetOnlineTrain));
              workerThread.Start();
           }
  </code></pre>
  
  <p>So in my <code>load form</code> i called this by thread:</p>
  
  <pre><code>   private bool stop = false;
      public void GetOnlineTrain()
      {
          try
          {
              while (stop!=true)
              {
                  TimeTableRepository objTimeTableREpository = new TimeTableRepository();
                  OnlineTrainList = objTimeTableREpository.GetAll().ToList();
                  objTimeTableREpository = null;
                  if(stop!=true)
                  Invoke(UpdateListBox);
                  else this.Dispose();
  
  
              }
          }
          catch(Exception a)
          {
          }
  
      }
  </code></pre>
  
  <p>My problem is when i want to show another form i got this error:</p>
  
  <pre><code>        stop = true;
          frmPath frmPath = new frmPath();
          frmPath.ShowDialog();
  </code></pre>
  
  <p>This error </p>
  
  <pre><code>  Cannot access a disposed object  -{System.ObjectDisposedException: Cannot access a disposed object.
  Object name: 'frmMain'.
     at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
     at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
     at System.Windows.Forms.Control.Invoke(Delegate method)
     at PresentationLayer.PreLayer.frmMain.GetOnlineTrain() in d:\TFS Project\Railway\ShirazMetro\PresentationLayer\PreLayer\frmMain.cs:line 167}
  </code></pre>
  
  <p>I got this error in <code>GetOnlineTrain</code> method .</p>
  
  <p>I <code>FrmPath</code> in <code>formload</code> when i put this line i got the above error ,but when i clear this line every thing works fine!!!!!!!</p>
  
  <pre><code>private void frmLine_Load(object sender, EventArgs e)
  {
      txtNumber.Focus();
  
      gvListLine.DataSource = objLineRepository.GetAll().ToList();
   }
  </code></pre>
  
  <p>Best regards </p>