获得跨线程操作的MdiParent无效 [英] Getting Cross-thread operation not valid in MDIParent
本文介绍了获得跨线程操作的MdiParent无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
跨线程操作无效
我想从另一个线程关闭窗体的基础。我收到以下错误。
System.InvalidOperationException:跨线程操作无效:控制'的MdiParent'从一个线程比它创建于其他线程访问
有以下行:
MDIParent.MDIParentRef.BaseClose();
解决方案
您需要在UI线程执行操作:
如果(InvokeRequired)
调用(新动作(MDIParent.MDIParentRef.BaseClose));
其他
MDIParent.MDIParentRef.BaseClose();
Possible Duplicate:
Cross-thread operation not valid
I am trying to close the base of a form from another thread. I am getting the following error.
System.InvalidOperationException: Cross-thread operation not valid: Control 'MDIParent' accessed from a thread other than the thread it was created on.
for the below line:
MDIParent.MDIParentRef.BaseClose();
解决方案
You need to perform the operation on the UI Thread:
if (InvokeRequired)
Invoke(new Action(MDIParent.MDIParentRef.BaseClose));
else
MDIParent.MDIParentRef.BaseClose();
这篇关于获得跨线程操作的MdiParent无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文