winform控件跨线程委托
1.
this.listBox1.BeginInvoke(new Action(() =>
{
if (listBox1.Items.Count > 20)
listBox1.Items.Clear();
listBox1.Items.Add(DateTime.Now + " ," + i+", "+ dtsource.Rows[i]["ID"] + " ,执行完成!");
listBox1.SelectedIndex = listBox1.Items.Count - 1;
}));
2.
delegate void AddItemCallback(string text);
private void AddItem(string text)
{
if (this.listBox1.InvokeRequired)
{
AddItemCallback d = new AddItemCallback(AddItem);
this.listBox1.Invoke(d, new object[] { text });
}
else
{
if (this.listBox1.Items.Count > 100)
listBox1.Items.Clear();
this.listBox1.Items.Add(text);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
}
}
3.
listBox1.BeginInvoke(new del(Monitorlist), new object[] { DateTime.Now + ",采集" + Dmodels.SHOPNAME + "," + Dmodels.AREAS_BIG + "," + Dmodels.AREAS_SMALL + " ,完成!" });
public void Monitorlist(string text)
{
if(this.listBox1.Items.Count>60)
{
this.listBox1.Items.Clear();
}
this.listBox1.Items.Add(text);
this.listBox1.SelectedIndex = listBox1.Items.Count - 1;
}
4.
public delegate void del2();
this.label2.BeginInvoke(new del2(() => { this.label2.Text = dt.Rows[i]["aNAME"].ToString().Trim(); }));
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步