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

标题: C# 错误:Cross-thread operation not valid: Control 'lblStatus' [打印本页]

作者: 资讯王    时间: 2012-2-18 14:46
标题: C# 错误:Cross-thread operation not valid: Control 'lblStatus'
错误: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. }
复制代码





欢迎光临 大马资讯论坛 - 马来西亚中文资讯平台 (http://freeinfo.com.my/) Powered by Discuz! X3.3