/// <summary> /// DataArrival事件处理函数(本程序中该函数是在接收线程【子线程】上执行) /// </summary> /// <param name="Data">接收的字节数组</param> /// <param name="Ip">远程主机的IP地址</param> /// <param name="Port">远程主机的端口</param> private void sockUDP1_DataArrival(byte[] Data, IPAddress Ip, int Port) { DataArrivaldelegate outdelegate = new DataArrivaldelegate(DataArrival);//初始化委托 //在控件线程【主线程】上异步执行操作(这里的异步是相当于子线程而言:将委托从子线程发到主线程,由主线程执行,子线程不等待断续执行后续操作) //因为需要更改控件属性,所以使用this.BeginInvoke将委托发到控件线程异步执行,若使用outdelegate.BeginInvoke,则会将委托发送到一个新线程异步执行,在非控件线程上是无法更改控属性的 this.BeginInvoke(outdelegate, new object[] { Data, Ip, Port }); }
private void udpSocket1_DataArrival(byte[] Data, IPAddress Ip, int Port) { DataArrivaldelegate outdelegate = new DataArrivaldelegate(DataArrival); this.BeginInvoke(outdelegate, new object[] { Data, Ip, Port }); }
private void socketUDP1_DataArrival(byte[] Data, IPAddress ip, int port) { DataArrivaldelegate outdelegate = new DataArrivaldelegate(DataArrival); this.BeginInvoke(outdelegate, new object[] { Data, ip, port }); }
private void sockUDP1_DataArrival(byte[] Data, System.Net.IPAddress Ip, int Port) { DataArrivaldelegate outdelegate = new DataArrivaldelegate(DataArrival); //托管 this.BeginInvoke(outdelegate, new object[] { Data, Ip, Port }); //异步执行托管 }
private void socketUDP1_DataArrival(byte[] Data, IPAddress ip, int port) { DataArrivaldelegate outdelegate = new DataArrivaldelegate(DataArrival); this.BeginInvoke(outdelegate, new object[] { Data, ip, port }); }
private void udpSocket1_DataArrival(byte[] Data, System.Net.IPAddress Ip, int Port) //当有数据到达后的处理进程 { DataArrivaldelegate outdelegate = new DataArrivaldelegate(DataArrival); //托管 this.BeginInvoke(outdelegate, new object[] { Data, Ip, Port }); //异步执行托管 }