c#中Invoke方法
阿新 • • 發佈:2019-01-30
using System.Threading;
public delegate void MyInvoke(string str);//invoke方法建立委託
private void btnStartThread_Click(object sender, EventArgs e)
{
Thread thread = new Thread(new ThreadStart(DoWord));
thread.Start();
}
public void DoWord()
{
MyInvoke mi = new MyInvoke(SetTxt);//例項化一個委託,並且指定委託方法
BeginInvoke(mi,new object[]{"abc"}); //呼叫invoke方法
}
public void SetTxt(string str)//委託對應的方法
{
txtReceive.Text += "invoke";
}
this.listView1.Invoke(new EventHandler(delegate
{
listView1.Items.RemoveAt(i);
}));