views:

46

answers:

1

I use this method to close forms according to their Id, but if I open a form with Id 2, close it once, it works fine, but if I open a form again with Id 2, it doesn't close the form (the form just stays on the screen). I have no idea what is going on and desperately need help. Thanks!

public void OutsideClose(long Id)
{
    if (InvokeRequired)
    {
        Invoke(new Action<long>(OutsideClose), Id);
    }
    else
    {
        var FormToClose = ListForms.Find(a=> a.Id == Id);
        if(FormToClose != null)
        {
            FormToClose.Dispose();
            OpenForms.Remove(Id);
        }
    }
}
+1  A: 

Ok, I am dumb! I was disposing the form, but I wasn't removing it from the list. Now I added a line of code to do that and now it's fixed.

Edit: Thanks Jon for making me look closer at the code (especially the two lists)

Soo