c#后台线程访问前台控件并显示信息示例
本文导语: 代码如下://设置为后台线程 Thread th = new Thread(delegate() { append();});th.IsBackground = true;th.Start(); //在append方法里面需要调用前台控件 public void append(){ // ... 业务处理 this.Invoke(new flushMessage(showMessage), new object[] { row["...
//设置为后台线程
Thread th = new Thread(delegate() {
append();
});
th.IsBackground = true;
th.Start();
//在append方法里面需要调用前台控件
public void append(){
// ... 业务处理
this.Invoke(new flushMessage(showMessage), new object[] { row["Code"].ToString(), res });
}
//委托flushMessage和方法showMessage签名必须一致
private delegate void flushMessage(String id, String res);
private void showMessage(String id,String res)
{
if (res == "true")
{
txtMsg.Text += "tttt" + id + "tttt导入成功rn";
}
else
{
txtMsg.Text += "tttt" + id + "ttttt导入失败rn";
}
}