Invoking Something Twice Leads To: "protected override void Dispose"
I have a function that helps me close forms without getting crossthread errors:
public void OutsideClose(long Id)
{
MessageBox.Show("");
if (InvokeRequired)
{
开发者_StackOverflow Invoke(new Action<long>(OutsideClose), Id);
}
else
{
var asdf = ListForm.Find(a => a.Id == Id);
if (asdf != null)
{
asdf.Close();
}
}
}
For some reason, if I call this invoke twice, instead of closing the form the second time, it goes to this dispose method:
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
I want the form to close, and have no idea what is going on...
asdf.Close should calls asdf.Dispose.
The form with the id should not be found the second time you call the method.
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();
}
精彩评论