C# 两次调用某个对象会导致:“引用”;“受保护的覆盖无效处置”;

C# 两次调用某个对象会导致:“引用”;“受保护的覆盖无效处置”;,c#,dispose,invoke,C#,Dispose,Invoke,我有一个函数可以帮助我关闭表单,而不会出现交叉线程错误: public void OutsideClose(long Id) { MessageBox.Show(""); if (InvokeRequired) { Invoke(new Action<long>(OutsideClose), Id); } else { var

我有一个函数可以帮助我关闭表单,而不会出现交叉线程错误:

    public void OutsideClose(long Id)
    {
        MessageBox.Show("");
        if (InvokeRequired)
        {
            Invoke(new Action<long>(OutsideClose), Id);
        }
        else
        {
            var asdf = ListForm.Find(a => a.Id == Id);
            if (asdf != null)
            {
                asdf.Close();
            }
        }
    }

我希望表单关闭,但不知道发生了什么…

asdf.close应该调用asdf.Dispose。

第二次调用该方法时,不应该找到id为的表单

        var asdf = ListForm.Find(a => a.Id == Id);
        if (asdf != null)
        {
            ListForm.Remove(asdf); //or whatever you need to do to remove it...
            asdf.Close();
        }

“而不是第二次关闭表单”。。。您肯定只能关闭一次表单吗?关闭表单后将调用
Dispose
方法。很抱歉,没有包含足够的代码,但列表项已在代码的其他部分中删除,否则您是正确的
        var asdf = ListForm.Find(a => a.Id == Id);
        if (asdf != null)
        {
            ListForm.Remove(asdf); //or whatever you need to do to remove it...
            asdf.Close();
        }