public partial class Form
{
private delegate void InvokeFunction( string msg); //1.宣告delegate 函數形式
private void TrueFunction(string msg) //2.delegate實際要做事情的函數,其函數的參數形式與其delegate要一致
{
this.txMsg.text = msg;
}
private void ThreadFunction()
{
string msg = "Message From Other Thread";
this.Invoke( new InvokeFunction( this.TrueFunction), new object[] {msg}); //3.thread內呼叫delegate (或者是onEvent內叫用)
}
void jc_OnFeedback(object sender, CommEventArgs e) //3.(或者是onEvent內叫用)
{
this.Invoke(new InvokeFunction(this.TrueFunction), new object[] { e.Message });
}