The c background thread accesses the foreground control and displays an example of the information

  • 2020-06-15 10:05:36
  • OfStack


// Set to background thread 
Thread th = new Thread(delegate() {
  append();
});
th.IsBackground = true;
th.Start();
// in append Method to call the foreground control 
public void append(){
  // ...  The business process 
  this.Invoke(new flushMessage(showMessage), new object[] { row["Code"].ToString(), res });
}
// entrust flushMessage And methods showMessage The signature must be 1 to 
private delegate void flushMessage(String id, String res);
private void showMessage(String id,String res)
{
if (res == "true")
{
txtMsg.Text += "\t\t\t\t" + id + "\t\t\t\t Import success \r\n"; 
}
else
{
txtMsg.Text += "\t\t\t\t" + id + "\t\t\t\t\t Import failure \r\n";
}
}


Related articles: