日期:2014-05-18 浏览次数:20926 次
private void delegate InvokeLabelText(); private void setLabelText() { if (this.InvokeRequired) { InvokeLabelText invokeLabelText = new InvokeLabelText(aa); this.Invoke(invokeLabelText); return; } setText(); } public void setText() { lock (this) { this.lblMsg.Text = Util.MSG; //Util.MSG我定义的一个变量,值总会改变 } }
private void delegate InvokeLabelText(string value); private void Form_Load(object sender, EventArgs e) { Thread thread = new Thread(setLabelText); thread.Start(); } private void setLabelText(string value) { if (this.InvokeRequired) { InvokeLabelText invokeLabelText = new InvokeLabelText(setLabelText); this.Invoke(invokeLabelText,value); } this.lblMsg.Text = value; }
------解决方案--------------------
private void setLabelText() { this.Invoke((MethodInvoker)(() => this.setText())); }