private delegate void SetListBoxCallBack(string str);//声名委托
private SetListBoxCallBack setlistboxcallback;//声名委托实例
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
setlistboxcallback = new SetListBoxCallBack(SetListBox);
Thread th = new Thread(new ThreadStart(Threadstart));//声名线线程
th.Start();//线程开始
}
private void SetListBox(string str)
{
listBox1.Items.Add(str);
}
private void Threadstart()
{
this.listBox1.Invoke(setlistboxcallback, "aa");//利用控件的invoke方法,其中参数为(委托,参数列表);
}