winform 跨线程设置控件属性

private delegate void SetLabelTextCallBack(Label l, String text);
/// <summary>
/// 为 Label 控件设置 Text 文本
/// </summary>
/// <param name="l">Label</param>
/// <param name="text">Text</param>
private void SetLabelText(Label l, String text)
{
     if (l.InvokeRequired)
     {
         SetLabelTextCallBack call = new SetLabelTextCallBack(SetLabelText);
         this.Invoke(call, new object[] { l, text });
      }
      else
     {
         l.Text = text;
      }
 }

 

posted @ 2021-08-19 00:20  随便取个名字算了  阅读(73)  评论(0编辑  收藏  举报