日期:2014-05-18 浏览次数:21031 次
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; public partial class Form2 : Form { public delegate void AddListItem(string s);//声明委托 public AddListItem myDelegate; public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { myDelegate = new AddListItem(AddtoListBox); aa AA = new aa(this); Thread th = new Thread(new ThreadStart(AA.tianjia));//开辟新线程 th.Start(); } public void AddtoListBox(string s) { listBox1.Items.Add(s);//给列表框添加一项 } } public class aa { Form2 frm; public aa(Form2 frm) { this.frm = frm; } public void tianjia() { for (int i = 0; i < 10; i++) { frm.Invoke(frm.myDelegate, new Object[] { i.ToString() });//委托调用 } } }