C#的handler.post runnable实现: delegate

时间:2021-06-03 17:29:51

关键字delegate在应用非常广泛,比如:

private delegate void dele_UpdateReceiptData(string data);

private void updateReceiptData(string data){

   this.text=data;

}

private void serialPort1_DataReceived(object sender,System.IO.Ports.SerialDataReceivedEventArgs e){

 string w_s=serialPort1.ReadLine();

this.Invoke(new dele_UpdateReceiptData(updateReceiptData),w_s); //在form所在的线程执行updateReceiptData动作.

}

但新版本C#应用更灵活:

https://msdn.microsoft.com/zh-cn/library/0yw3tz5k.aspx