在MDIParent 中使跨线程操作无效

可能重复:
跨线程操作无效

我试图从另一个线程关闭表单的基础。 我收到以下错误。

System.InvalidOperationException:跨线程操作无效:从创建它的线程以外的线程访问控制’MDIParent’。

对于以下行:

MDIParent.MDIParentRef.BaseClose(); 

您需要在UI线程上执行操作:

 if (InvokeRequired) Invoke(new Action(MDIParent.MDIParentRef.BaseClose)); else MDIParent.MDIParentRef.BaseClose();