大马资讯论坛 - 马来西亚中文资讯平台

 找回密码
 注册
搜索
打印 上一主题 下一主题

C# 错误:Cross-thread operation not valid: Control 'lblStatus'

[复制链接]
跳转到指定楼层
1#
发表于 2012-2-18 14:46:14 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
错误:Cross-thread operation not valid: Control 'lblStatus' accessed from a thread other than the thread it was created on.

解决方案:

  1. public void SetStatus(string msg)
  2. {
  3.     if (lblStatus.InvokeRequired)
  4.         lblStatus.Invoke(new MethodInvoker(delegate
  5.         {
  6.             lblStatus.Text = msg;
  7.         }));
  8.     else
  9.         lblStatus.Text = msg;
  10. }
复制代码

手机版|大马资讯论坛  

GMT+8, 2024-12-1 18:47 , Processed in 0.016695 second(s), 11 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表