winform多线程修改界面lable
winform非主线程界面, 非主线程修改界面
方法1:
使用lamda表达式
this.lblFixStatus = new System.Windows.Forms.Label(); if(lblFixStatus.InvokeRequired) { lblFixStatus.Invoke(new Action(() => lblFixStatus.Text = dir)); } else { this.lblFixStatus.Text = dir; }
方法2:
使用委托
this.lblFixStatus = new System.Windows.Forms.Label(); //定义委托 public delegate void UpdateProcess(string txt); private UpdateProcess updateLabelText public winform类构造函数() { updateLabelText += new UpdateProcess(UpdatelblStatus); } private void UpdatelblStatus(string txt) { lblFixStatus.Text = txt; } //子线程调用 lblFixStatus.Invoke(updateLabelText, "状态正常");