创建委托
1:
//定时器,执行委托线程事件
private static System.Timers.Timer GetCrossTimer;
//自定义委托
private delegate void ListenServerDelegate(string text);
private ListenServerDelegate listenServerDelegate;
2:
private void MainWindow_Load(object sender, EventArgs e)
{
//赋予委托函数
listenServerDelegate = new ListenServerDelegate(SetThreadText);
}
3:
private void TimerElapsed(...){
//执行委托,将轮询线程中的参数赋值到主线程中的label3字段
string label3Text = "test_test_test";
this.Invoke(listenServerDelegate, new object[] { label3Text });
}