多线程 更新 winform 控件的值,以避免UI线程的卡顿

委托

private delegate void UpdateDGV_AddRes_CallBack(Int32 i,bool Res);

函数实现

private void UpdateDGV_DevAddResult(Int32 i, bool Res)
{
            if (this.DGV_DevAddResult.InvokeRequired)
            {
                UpdateDGV_AddRes_CallBack d = new UpdateDGV_AddRes_CallBack(UpdateDGV_DevAddResult);
                this.Invoke(d, new object[] { i ,Res});
            }
            else
            {
                //具体功能代码...
                //如,textbox1.text=“hello,world”

            }     
}

子线程这样调用:

UpdateDGV_DevAddResult(i,Res);

猜你喜欢

转载自www.cnblogs.com/Chendezhou/p/9209692.html