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(); }));