public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button1;
...
private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(this.ThreadProc);
thread.Start();
}
private void ThreadProc()
{
for (int i = 0; i < 10; i++)
{
this.Invoke((MethodInvoker)delegate
{
this.listBox1.Items.Add("Item " + (i + 1).ToString());
});
}
}
}
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/










