日期:2019-11-14 浏览次数:46次

方法1:

 txtState.Invoke(new Action(() => { txtState.Text = "要显示的内容"; }));

更新多个控件 可以这样:

if (IsDisposed || !this.IsHandleCreated) return;
 // if (IsDisposed ||!this.Parent.IsHandleCreated) return;

this.BeginInvoke(new Action(() => {
                txt1.Text = "txt1";
                txt2.Text = "txt2";
                txt3.Text = "txt3";
                txt4.Text = "txt4"; 
            }));

方法2:


        /// <summary>
        /// 设置实时状态label 文本
        /// </summary>
        /// <param name="runInfo"></param>
        delegate void SetTextLabStateNowCallBack(string runInfo); 


        

        /// <summary>
        /// 设置实时状态
        /// </summary>
        /// <param name="runInfo"></param>
        private void SetLabState_NowText(string runInfo)
        {
            if (!this.IsDisposed)
            {
                if (this.labState_Now.InvokeRequired)
                {
                    SetTextLabStateNowCallBack stcb = new SetTextLabStateNowCallBack(SetLabState_NowText);
                    this.Invoke(stcb, new object[] { runInfo });
                }
                else
                {
                    this.labState_Now.Text = runInfo + " " + DateTime.Now;
                }
            }
        }

方法3: