资讯王 发表于 2012-2-18 14:46:14

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.

解决方案:
public void SetStatus(string msg)
{
    if (lblStatus.InvokeRequired)
      lblStatus.Invoke(new MethodInvoker(delegate
      {
            lblStatus.Text = msg;
      }));
    else
      lblStatus.Text = msg;
}
页: [1]
查看完整版本: C# 错误:Cross-thread operation not valid: Control 'lblStatus'