线程异步调用方法

private void button1_Click(object sender, EventArgs e)
{
System.Threading.Thread thread = new System.Threading.Thread(() =>
{
setText("TTTT");
});

thread.IsBackground = true;
thread.Start();
}
private delegate void setRichTexBox(string s);
public void setText(string txt)
{
if (this.textBox1.InvokeRequired)//等待异步
{
setRichTexBox fc = new setRichTexBox(Set);
this.Invoke(fc, new object[] { txt });
}
else
{
this.textBox1.AppendText(txt);
}
}

private void Set(string txt)
{
textBox1.AppendText(txt);
}

posted @ 2018-06-19 12:06  华翎科技  阅读(187)  评论(0)    收藏  举报