objectlistviewobjectdisposedexception

Can not access disposed object in CellEditFinished event popup messages of ObjectListView


When I click on the 'Open Modal Window' button in [Main form], it shows the [subform] that is built with a data list by using the ObjectListView component.

When I click on the "Age" column to edit it and changed the value in the cell to be a non zero value, then click on the blank of the ObjectListView component(if I press Enter, the exception will not come out), it popup a message. I left this message in front of all the opened windows and wait 10 seconds for the application timeout. At that time, an exception shows:

Cannot access a disposed object. Object name: 'ObjectListView'.

Here is the code:

private void button1_Click(object sender, EventArgs e)
{
    modalForm = new Form2();
    StartTimeOutTimer();
    var result = modalForm.ShowDialog(this);
}

private void ProcessTimeOut()
{
    timer1.Stop();
    seconds = 0;
    List<Form> openForms = Application.OpenForms.Cast<Form>().Where(frm => !string.Equals(frm.Name, "Form1") && !frm.IsDisposed).ToList();
    for (var i = openForms.Count - 1; i >= 0; i--)
    {
        openForms[i].Dispose();
    }
}

private void timer1_Tick(object sender, EventArgs e)
{
    seconds++;
    if (seconds == 10)
    {
        ProcessTimeOut();
    }
}

the exception come out in this line:

var result = modalForm.ShowDialog(this);

My reputation is too low to upload more links, so I post the code to OneDrive. The sample code and solution is here:

https://1drv.ms/u/s!AmQYEYkCV6gqgw6iPMVFPBKlSx1V

I tried to add the source code of ObjectListView in my solution, and the error occurred in the GetHeaderControl method in the source code of v2.9.0

Please download my sample code to reproduce the exception. How do I fix this exception? Any suggestion will be appreciated.


Solution

  • I download the code and it seems a bug of objeclistview. I cannot fix it, but I have a workaround to resolve your issue: you can ShowDialog() by asynchronously, like this:

     this.BeginInvoke(new Action(() => {
             var myMsgBox = new MyMsgBox("Must be 0");
             myMsgBox.ShowDialog();
          }));