加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 跨线程Winforms控件编辑

发布时间:2020-12-15 20:05:05 所属栏目:百科 来源:网络整理
导读:参见英文答案 Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on????????????????????????????????????20个 如果正在编辑文本的代码“属于”包含Windows窗体的单独线程,如何编辑windows窗体元素中
参见英文答案 > Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on????????????????????????????????????20个
如果正在编辑文本的代码“属于”包含Windows窗体的单独线程,如何编辑windows窗体元素中的文本?我得到了例外:

Cross-thread operation not valid: Control ‘textBox1’ accessed from a thread other than the thread it was created on.

谢谢.

解决方法

你需要使用这样的 Control.Invoke方法:

textbox1.Invoke((MethodInvoker)(() =>
   {
     textbox1.Text="some text";
   }));

也请查看这篇文章:Threading in UIs

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读