C# 2.0 匿名方法与 Windows Forms 异步调用
来源:岁月联盟
时间:2004-10-09
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());
});
}
}
}
下一篇:XML操作类